package com.hanhai.material.device.controller;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.fastjson.JSONObject;
import com.hanhai.material.common.result.KingdeeResult;
import com.hanhai.material.common.result.Result;
import com.hanhai.material.common.result.ResultTool;
import com.hanhai.material.device.entity.*;
import com.hanhai.material.device.mapper.FormProductDayReportMapper;
import com.hanhai.material.device.model.ProductRecordIntoModel;
import com.hanhai.material.device.model.TransferModel;
import com.hanhai.material.device.model.excel.ProductBadDataExcel;
import com.hanhai.material.device.model.miscellaneousdelivery.MiscellaneousDelivery;
import com.hanhai.material.device.model.product.ProductReceiptData;
import com.hanhai.material.device.service.*;
import com.hanhai.material.device.utils.kingdee.KingdeeUtils;
import com.hanhai.material.device.utils.kingdee.ProductReceiptUtil;
import com.hanhai.material.device.utils.kingdee.TransferDataUtil;
import com.hanhai.material.scheduling.entity.SysProductPeople;
import com.hanhai.material.scheduling.service.SysProductPeopleService;
import com.hanhai.material.utils.excel.ExcelUtils;
import com.hanhai.material.utils.jiandaoyun.PushToJianDaoYunUtil;
import com.hanhai.material.utils.redis.RedisUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.relation.RelationManager;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StopWatch;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;

import static com.hanhai.material.device.entity.table.FormingProductDayBadDetailDOTableDef.FORMING_PRODUCT_DAY_BAD_DETAIL_D_O;
import static com.hanhai.material.device.entity.table.FormingProductDayPendingIntoDetailDOTableDef.FORMING_PRODUCT_DAY_PENDING_INTO_DETAIL_D_O;
import static com.hanhai.material.device.entity.table.SysBadRecordTableDef.SYS_BAD_RECORD;
import static com.hanhai.material.device.entity.table.SysProductRecordDetentionRecordTableDef.SYS_PRODUCT_RECORD_DETENTION_RECORD;
import static com.hanhai.material.device.entity.table.SysProductRecordIntoTableDef.SYS_PRODUCT_RECORD_INTO;
import static com.hanhai.material.scheduling.entity.table.SysProductPeopleTableDef.SYS_PRODUCT_PEOPLE;
import static com.hanhai.material.utils.TimeUtils.fromDateToString;
import static com.mybatisflex.core.query.QueryMethods.distinct;
import static com.mybatisflex.core.query.QueryMethods.sum;

/**
 * 控制层。
 *
 * @author youchuang
 * @since 2024/02/16 15:49:52
 */
@RestController
@RequestMapping("/product_record_into")
@Log4j2
public class SysProductRecordIntoController {

    @Autowired
    private SysProductRecordIntoService sysProductRecordIntoService;

    @Autowired
    private SysProductRecordDetentionRecordService sysProductRecordDetentionRecordService;

    @Autowired
    private SysProductRecordDetentionService sysProductRecordDetentionService;

    @Autowired
    private PushToJianDaoYunUtil pushToJianDaoYunUtil;
    @Autowired
    AsyncService asyncService;

    @Autowired
    ProductReceiptUtil productReceiptUtil;

    @Autowired
    TransferDataUtil transferDataUtil;
    @Autowired
    RedisUtil redisUtil;
    @Autowired
    SysProductRecordShiftService sysProductRecordShiftService;

    @Autowired
    SysProductPeopleService sysProductPeopleService;

    @Resource
    private FormProductDayReportMapper formProductDayReportMapper;

    @Resource
    private FormingProductDayBadDetailService formingProductDayBadDetailService;

    @Resource
    private FormingProductDayPendingIntoService formingProductDayPendingIntoService;


    /**
     * 添加。
     *
     * @param sysProductRecordInto
     * @return {@code true} 添加成功，{@code false} 添加失败
     */
    @PostMapping("save")
    public Result<?> save(@RequestBody SysProductRecordInto sysProductRecordInto) throws IOException {
//        String id=UUID.randomUUID().toString();

        String id = fromDateToString("yyyyMMdd", sysProductRecordInto.getProductDate()) + sysProductRecordInto.getMachineName() + sysProductRecordInto.getWorkPlanId() + sysProductRecordInto.getProductId() + sysProductRecordInto.getShift();
        if (this.redisUtil.hget("productIntoData", id) == null) {

            this.redisUtil.hset("productIntoData", id, id, 6 * 10);
            sysProductRecordInto.setId(id);
            String pid = saveToPg(sysProductRecordInto, false);
            sysProductRecordInto.setDataId(pid);
            boolean result = this.sysProductRecordIntoService.save(sysProductRecordInto);
            return result ? ResultTool.success() : ResultTool.fail();
        } else {

            return ResultTool.fail("入库数据已存在！");
        }
    }


    public String saveToPg(SysProductRecordInto sysProductRecordInto, Boolean isUpdate) {
        SysProductInfo productInfo = sysProductRecordInto.getProductInfo();
        SysWorkPlan workPlan = sysProductRecordInto.getWorkPlan();
        SysProductRecordShift sysProductRecordShift = sysProductRecordInto.getProductRecordShift();
        if (productInfo == null || workPlan == null) {
            return null;
        }
        FormingProductDayReportDO formingProductDayReportDO = new FormingProductDayReportDO();
        formingProductDayReportDO.setId(sysProductRecordInto.getId());
        formingProductDayReportDO.setReporter(String.valueOf(1));
        formingProductDayReportDO.setReporterName("超级管理员");
        formingProductDayReportDO.setCreator("1");
        formingProductDayReportDO.setUpdater("1");
        formingProductDayReportDO.setProductDate(sysProductRecordInto.getProductDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime());
        formingProductDayReportDO.setShiftCode(sysProductRecordInto.getShiftCode());
        formingProductDayReportDO.setShift(sysProductRecordInto.getShift().equals("白班") ? 1 : 0);
        formingProductDayReportDO.setMachineName(sysProductRecordInto.getMachineName());
        formingProductDayReportDO.setProductStartTime(sysProductRecordInto.getActualStartTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime());
        formingProductDayReportDO.setProductEndTime(sysProductRecordInto.getActualEndTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime());
        formingProductDayReportDO.setTotalCount(sysProductRecordInto.getTotalCount());
        formingProductDayReportDO.setWorkPlanId(sysProductRecordInto.getWorkPlanId());
        formingProductDayReportDO.setIsAuto(1);
        Duration duration = Duration.between(formingProductDayReportDO.getProductStartTime(), formingProductDayReportDO.getProductEndTime());
        formingProductDayReportDO.setActualWorkTimeNum(BigDecimal.valueOf((duration.toMinutes() - sysProductRecordInto.getAdjustMachineDuration()) / 60).setScale(2, RoundingMode.HALF_UP));
        int standardCapacity = (int) (3600 * formingProductDayReportDO.getActualWorkTimeNum().doubleValue() * workPlan.getMoldNumber() / productInfo.getStandardCycle());
        formingProductDayReportDO.setStandardNum(standardCapacity);
        int actualCapacity = sysProductRecordShift.getGoodNumPeople() + sysProductRecordShift.getBadNumPeople() + sysProductRecordInto.getDetentionNum() + sysProductRecordInto.getWillProcessedNum() + sysProductRecordInto.getNowTailBoxCount();
        formingProductDayReportDO.setActualNum(actualCapacity);
        double actualCycle = (double) 3600 * formingProductDayReportDO.getActualWorkTimeNum().doubleValue() * workPlan.getMoldNumber() / actualCapacity;
        formingProductDayReportDO.setActualCycle(BigDecimal.valueOf(actualCycle));
        formingProductDayReportDO.setStandardRecycle(BigDecimal.valueOf(productInfo.getStandardCycle()));
        formingProductDayReportDO.setProductId(productInfo.getProductId());
        formingProductDayReportDO.setProductName(workPlan.getProductName());
        formingProductDayReportDO.setCustomerName(productInfo.getCustomerName());
        formingProductDayReportDO.setMachineTypeName(productInfo.getMachineType());
        formingProductDayReportDO.setMachineItemName(productInfo.getMachineItem());
        formingProductDayReportDO.setMoldNo(workPlan.getMoldNo());
        formingProductDayReportDO.setMoldCaveNum((int) workPlan.getMoldNumber());
        formingProductDayReportDO.setPeopleNum((int) workPlan.getMoldNumber());
        formingProductDayReportDO.setGoodNum(sysProductRecordShift.getGoodNumPeople());
        formingProductDayReportDO.setTotalBadNum(sysProductRecordInto.getBadNumPeople());
        formingProductDayReportDO.setDetentionNum(sysProductRecordInto.getDetentionNum() + sysProductRecordInto.getWillProcessedNum());
        formingProductDayReportDO.setTailBoxNum(sysProductRecordInto.getNowTailBoxCount());
        formingProductDayReportDO.setLastTailBoxNum(sysProductRecordInto.getLastTailBoxCount());
        formingProductDayReportDO.setLineManagerName(sysProductRecordInto.getUserName());
        formingProductDayReportDO.setLineManagerJobNo(sysProductRecordInto.getJobNo());
        formingProductDayReportDO.setAdjustTime(BigDecimal.valueOf(sysProductRecordInto.getAdjustMachineDuration()));
        if(sysProductRecordInto.getAdjustMachineDuration()>0){
            formingProductDayReportDO.setAdjustReason(sysProductRecordInto.getAdjustMachineReason().replaceAll("null",""));
        }
        QueryWrapper queryWrapper = QueryWrapper.create();
//        queryWrapper.where(SYS_BAD_RECORD.CREATE_TIME.between(productRecordInto.getActualStartTime(),productRecordInto.getActualEndTime()));
        queryWrapper.where(SYS_BAD_RECORD.WORK_PLAN_ID.eq(workPlan.getWorkPlanId()));
        queryWrapper.where(SYS_BAD_RECORD.PRODUCT_DATE.eq(fromDateToString("yyyy-MM-dd", sysProductRecordInto.getProductDate())));
        queryWrapper.where(SYS_BAD_RECORD.SHIFT.eq(sysProductRecordInto.getShift()));
        queryWrapper.where(SYS_BAD_RECORD.REASON_TYPE.ne("品质领取"));
        queryWrapper.select(SYS_BAD_RECORD.PRODUCT_ID, sum(SYS_BAD_RECORD.NUM).as("num"), SYS_BAD_RECORD.REASON_TYPE, SYS_BAD_RECORD.REASON_NAME);
        queryWrapper.groupBy(SYS_BAD_RECORD.REASON_TYPE, SYS_BAD_RECORD.REASON_NAME);
        List<SysBadRecord> badRecordList = this.sysBadRecordService.list(queryWrapper);

        int baseNum = 0;
        int manufactureBadNum = 0;
        int processBadNum = 0;
        int productBadNum = 0;
        int totalBadNum = 0;
        List<FormingProductDayBadDetailDO> badDetailDOList = new ArrayList<>();
        FormingProductDayBadDetailDO badDetailDO = new FormingProductDayBadDetailDO();
        for (SysBadRecord badRecord : badRecordList) {
            totalBadNum += badRecord.getNum();
            switch (badRecord.getReasonType()) {
                case "制程不良":
                    badDetailDO = new FormingProductDayBadDetailDO();
                    badDetailDO.setId(UUID.randomUUID().toString());
                    badDetailDO.setNum(badRecord.getNum());
                    badDetailDO.setReasonTypeName(badRecord.getReasonType());
                    badDetailDO.setReasonName(badRecord.getReasonName());
                    badDetailDO.setProductDayReportId(formingProductDayReportDO.getId());

                    manufactureBadNum += badRecord.getNum();
                    badDetailDOList.add(badDetailDO);
                    break;

                case "加工不良":
                    badDetailDO = new FormingProductDayBadDetailDO();
                    badDetailDO.setId(UUID.randomUUID().toString());
                    badDetailDO.setNum(badRecord.getNum());
                    badDetailDO.setReasonTypeName(badRecord.getReasonType());
                    badDetailDO.setReasonName(badRecord.getReasonName());
                    badDetailDO.setProductDayReportId(formingProductDayReportDO.getId());
                    manufactureBadNum += badRecord.getNum();
                    badDetailDOList.add(badDetailDO);

                    break;
                default:
                    badDetailDO = new FormingProductDayBadDetailDO();
                    badDetailDO.setId(UUID.randomUUID().toString());
                    badDetailDO.setNum(badRecord.getNum());
                    badDetailDO.setReasonTypeName("基础不良");
                    badDetailDO.setReasonName(badRecord.getReasonName());
                    badDetailDO.setProductDayReportId(formingProductDayReportDO.getId());
                    manufactureBadNum += badRecord.getNum();
                    badDetailDOList.add(badDetailDO);

                    break;
            }

        }
        queryWrapper = QueryWrapper.create();
//        queryWrapper.where(SYS_PRODUCT_PEOPLE.WORK_TIME.ge(fromDateToString("yyyy-MM-dd HH:00:00",productRecordInto.getActualStartTime())));
//        queryWrapper.where(SYS_PRODUCT_PEOPLE.WORK_TIME.lt(productRecordInto.getActualEndTime()));
//        queryWrapper.where(SYS_PRODUCT_PEOPLE.MACHINE_NAME.eq(productRecordShift.getMachineName()));
//        queryWrapper.where(SYS_PRODUCT_PEOPLE.WORK_PLAN_ID.eq(productRecordInto.getWorkPlanId()));
        queryWrapper.where(SYS_PRODUCT_PEOPLE.MACHINE_NAME.eq(sysProductRecordInto.getMachineName()));
        queryWrapper.where(SYS_PRODUCT_PEOPLE.SHIFT.eq(sysProductRecordInto.getShift()));
        queryWrapper.where(SYS_PRODUCT_PEOPLE.WORK_DATE.eq(fromDateToString("yyyy-MM-dd", sysProductRecordInto.getProductDate())));
        queryWrapper.select(distinct(SYS_PRODUCT_PEOPLE.JOB_NO), SYS_PRODUCT_PEOPLE.USER_NAME);
        List<SysProductPeople> productPeopleList = this.sysProductPeopleService.list(queryWrapper);
        int i = 0;
        StringJoiner userNameList = new StringJoiner(",");
        StringJoiner jobNoList = new StringJoiner(",");
        for (SysProductPeople productPeople : productPeopleList) {
            userNameList.add(productPeople.getUserName());
            jobNoList.add(productPeople.getJobNo());
            i++;

        }
        formingProductDayReportDO.setPeopleNum(i);
        formingProductDayReportDO.setRemarkName(jobNoList.toString());
        formingProductDayReportDO.setRemark(userNameList.toString());
        formingProductDayReportDO.setLineManagerJobNo(sysProductRecordInto.getCreateUserId());
        formingProductDayReportDO.setLineManagerName(sysProductRecordInto.getCreateUserName());
        queryWrapper = QueryWrapper.create();
        queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION_RECORD.PRODUCT_RECORD_INTO_ID.eq(sysProductRecordInto.getId()));
        queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION_RECORD.TYPE.eq("良品"));
        queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION_RECORD.NUM.gt(0));
        queryWrapper.groupBy(SYS_PRODUCT_RECORD_DETENTION_RECORD.PRODUCT_DATE);
        List<SysProductRecordDetentionRecord> sysProductRecordDetentionRecordList = this.sysProductRecordDetentionRecordService.list(queryWrapper);
        List<FormingProductDayPendingIntoDetailDO> pendingIntoValues = new ArrayList<>();
        for (SysProductRecordDetentionRecord sysProductRecordDetentionRecord : sysProductRecordDetentionRecordList) {
            FormingProductDayPendingIntoDetailDO formingProductDayPendingIntoDetailDO = new FormingProductDayPendingIntoDetailDO();
            formingProductDayPendingIntoDetailDO.setId(UUID.randomUUID().toString());
            formingProductDayPendingIntoDetailDO.setProductDate(sysProductRecordDetentionRecord.getProductDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime());
            formingProductDayPendingIntoDetailDO.setNum(sysProductRecordDetentionRecord.getNum());
            formingProductDayPendingIntoDetailDO.setProductDayReportId(formingProductDayReportDO.getId());
            pendingIntoValues.add(formingProductDayPendingIntoDetailDO);

        }
        formingProductDayReportDO.setTodayIntoNum(sysProductRecordShift.getGoodNumPeople() + sysProductRecordInto.getWillProcessedToGoodNum() + sysProductRecordInto.getDetentionToGoodNum() + sysProductRecordInto.getLastTailBoxCount() + sysProductRecordInto.getLastTailCountInto());
        formingProductDayReportDO.setInputQuantity(sysProductRecordShift.getGoodNumPeople() + sysProductRecordInto.getBadNumPeople() + sysProductRecordInto.getDetentionNum() + sysProductRecordInto.getWillProcessedNum() + sysProductRecordInto.getNowTailBoxCount());
        if (isUpdate) {
            formingProductDayReportDO.setUpdateTime(LocalDateTime.now());
            formProductDayReportMapper.update(formingProductDayReportDO);
        } else {
            formingProductDayReportDO.setCreateTime(LocalDateTime.now());
            formProductDayReportMapper.insert(formingProductDayReportDO);

        }
        if (CollectionUtils.isNotEmpty(badDetailDOList)) {
            formingProductDayBadDetailService.saveBatch(badDetailDOList);
        }
        if (CollectionUtils.isNotEmpty(pendingIntoValues)) {
            formingProductDayPendingIntoService.saveBatch(pendingIntoValues);
        }


        return formingProductDayReportDO.getId();
    }

    /**
     * 添加。
     *
     * @param sysProductRecordInto
     * @return {@code true} 添加成功，{@code false} 添加失败
     */
    @PostMapping("saveBatch")
    public Result<?> saveBatch(@RequestBody SysProductRecordInto sysProductRecordInto) {
        boolean result = this.sysProductRecordIntoService.save(sysProductRecordInto);
        return result ? ResultTool.success() : ResultTool.fail();
    }

    /**
     * 根据主键删除。
     *
     * @param id 主键
     * @return {@code true} 删除成功，{@code false} 删除失败
     */
    @DeleteMapping("remove/{id}")
    public boolean remove(@PathVariable Serializable id) {
        return sysProductRecordIntoService.removeById(id);
    }

    /**
     * 根据主键更新。
     *
     * @param productRecordInto
     * @return {@code true} 更新成功，{@code false} 更新失败
     */
    @PostMapping("update")
    public Result<?> update(@RequestBody SysProductRecordInto productRecordInto) throws IOException {
        log.error("ProductInfo:{}", JSONObject.toJSONString(productRecordInto));
        boolean result = this.sysProductRecordIntoService.updateById(productRecordInto);
        if (result) {
//            CountDownLatch countDownLatch = new CountDownLatch(1);
//            this.asyncService.updateProductRecordIntoByAsync(productRecordInto, countDownLatch);
            if (productRecordInto.getDataId() != null) {
                QueryWrapper queryWrapper = QueryWrapper.create();
                queryWrapper.where(FORMING_PRODUCT_DAY_BAD_DETAIL_D_O.PRODUCT_DAY_REPORT_ID.eq(productRecordInto.getId()));
                formingProductDayBadDetailService.remove(queryWrapper);
                log.info("SQL:{}", queryWrapper.toSQL());


                queryWrapper = QueryWrapper.create();
                queryWrapper.where(FORMING_PRODUCT_DAY_PENDING_INTO_DETAIL_D_O.PRODUCT_DAY_REPORT_ID.eq(productRecordInto.getId()));
                log.info("SQL:{}", queryWrapper.toSQL());
                formingProductDayPendingIntoService.remove(queryWrapper);


            }
            saveToPg(productRecordInto, true);

        }
        return result ? ResultTool.success(productRecordInto) : ResultTool.fail();
    }

    /**
     * 查询所有。
     *
     * @return 所有数据
     */
    @PostMapping("list")
    public Result<?> list(@RequestBody SysProductRecordInto sysProductRecordInto) {
        log.error("SYSPRODUCTRECORDINFO:{}", JSONObject.toJSONString(sysProductRecordInto));
        QueryWrapper queryWrapper = QueryWrapper.create();
//        if(sysProductRecordInto.getShift()!=null){
//            queryWrapper.where(SYS_PRODUCT_RECORD_INTO.SHIFT.eq(sysProductRecordInto.getShift()));
//        }
//        if(sysProductRecordInto.getMachineArea()!=null){
//            queryWrapper.where(SYS_PRODUCT_RECORD_INTO.MACHINE_AREA.eq(sysProductRecordInto.getMachineArea()));
//        }
        queryWrapper.where(SYS_PRODUCT_RECORD_INTO.MACHINE_NAME.isNotNull());
        queryWrapper.where(SYS_PRODUCT_RECORD_INTO.PRODUCT_ID.isNotNull());
//        queryWrapper.select(SYS_PRODUCT_RECORD_INTO.WORK_PLAN_ID, SYS_PRODUCT_RECORD_INTO.IS_ENTRY,SYS_PRODUCT_RECORD_INTO.PRODUCT_ID, SYS_PRODUCT_RECORD_INTO.MACHINE_AREA,
//                SYS_PRODUCT_RECORD_INTO.MACHINE_NAME, SYS_PRODUCT_RECORD_INTO.SHORT_NAME, SYS_PRODUCT_RECORD_INTO.PRODUCT_NAME, SYS_PRODUCT_RECORD_INTO.SHIFT, SYS_PRODUCT_RECORD_INTO.SHIFT_CODE,
//                SYS_PRODUCT_RECORD_INTO.GOOD_NUM_PEOPLE, SYS_PRODUCT_RECORD_INTO.BAD_NUM_PEOPLE, SYS_PRODUCT_RECORD_INTO.WILL_PROCESSED_TO_GOOD_NUM,
//                SYS_PRODUCT_RECORD_INTO.WILL_PROCESSED_TO_BAD_NUM, SYS_PRODUCT_RECORD_INTO.DETENTION_TO_GOOD_NUM, SYS_PRODUCT_RECORD_INTO.DETENTION_TO_BAD_NUM, SYS_PRODUCT_RECORD_INTO.WILL_PROCESSED_NUM, SYS_PRODUCT_RECORD_INTO.DETENTION_NUM,
//                SYS_PRODUCT_RECORD_INTO.TOTAL_HANDLE_INTO, SYS_PRODUCT_RECORD_INTO.TOTAL_TODAY_PEOPLE_INTO, SYS_PRODUCT_RECORD_INTO.PRODUCT_DATE);

        queryWrapper.where(SYS_PRODUCT_RECORD_INTO.PRODUCT_DATE.between(sysProductRecordInto.getStartDate(), sysProductRecordInto.getEndDate()));
        queryWrapper.orderBy(SYS_PRODUCT_RECORD_INTO.MACHINE_NAME, true);
        queryWrapper.orderBy(SYS_PRODUCT_RECORD_INTO.PRODUCT_ID, true);
        List<SysProductRecordInto> sysProductRecordIntoList = this.sysProductRecordIntoService.getMapper().selectListWithRelationsByQuery(queryWrapper);
        return sysProductRecordIntoList.isEmpty() ? ResultTool.fail() : ResultTool.success(sysProductRecordIntoList);
    }

    /**
     * 根据主键获取详细信息。
     *
     * @param productRecordShiftId 主键
     * @return 详情
     */
    @GetMapping("getInfo/{productRecordShiftId}")
    public Result<?> getInfo(@PathVariable String productRecordShiftId) {
        QueryWrapper queryWrapper = QueryWrapper.create();
        queryWrapper.where(SYS_PRODUCT_RECORD_INTO.PRODUCT_RECORD_SHIFT_ID.eq(productRecordShiftId));
        queryWrapper.limit(1);
        SysProductRecordInto sysProductRecordInto = this.sysProductRecordIntoService.getOne(queryWrapper);
        return sysProductRecordInto != null ? ResultTool.success(sysProductRecordInto) : ResultTool.fail();
    }

    @PostMapping("listByCondition")
    public Result<?> listByCondition(@RequestBody SysProductRecordInto productRecordInto) {
        QueryWrapper queryWrapper = QueryWrapper.create();
        queryWrapper.where(SYS_PRODUCT_RECORD_INTO.WORK_PLAN_ID.eq(productRecordInto.getWorkPlanId()));
        List<SysProductRecordInto> productRecordIntoList = this.sysProductRecordIntoService.list(queryWrapper);
        return productRecordIntoList.isEmpty() ? ResultTool.fail() : ResultTool.success(productRecordIntoList);
    }

    @Autowired
    KingdeeUtils kingdeeUtils;

    @PostMapping("addReceiptBatch/{productDate}")
    public Result<?> addReceiptBatch(@RequestBody List<SysProductRecordInto> productRecordIntoList, @PathVariable String productDate) throws IOException {
        log.error("SysP:{}", JSONObject.toJSONString(productRecordIntoList));
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        List<SysProductRecordInto> lightAProductRecordIntoList = new ArrayList<>();
        List<SysProductRecordInto> nightAProductRecordIntoList = new ArrayList<>();
        List<SysProductRecordInto> lightBProductRecordIntoList = new ArrayList<>();
        List<SysProductRecordInto> nightBProductRecordIntoList = new ArrayList<>();

        List<SysProductRecordInto> wc1la = new ArrayList<>();
        List<SysProductRecordInto> wc2la = new ArrayList<>();
        List<SysProductRecordInto> yd1171la = new ArrayList<>();
        List<SysProductRecordInto> yd1172la = new ArrayList<>();
        List<SysProductRecordInto> p2la = new ArrayList<>();
        List<SysProductRecordInto> p1la = new ArrayList<>();
        List<SysProductRecordInto> opla = new ArrayList<>();

        List<SysProductRecordInto> wc1lb = new ArrayList<>();
        List<SysProductRecordInto> wc2lb = new ArrayList<>();
        List<SysProductRecordInto> yd1171lb = new ArrayList<>();
        List<SysProductRecordInto> yd1172lb = new ArrayList<>();
        List<SysProductRecordInto> p2lb = new ArrayList<>();
        List<SysProductRecordInto> p1lb = new ArrayList<>();
        List<SysProductRecordInto> oplb = new ArrayList<>();

        List<SysProductRecordInto> wc1na = new ArrayList<>();
        List<SysProductRecordInto> wc2na = new ArrayList<>();
        List<SysProductRecordInto> yd1171na = new ArrayList<>();
        List<SysProductRecordInto> yd1172na = new ArrayList<>();
        List<SysProductRecordInto> p2na = new ArrayList<>();
        List<SysProductRecordInto> p1na = new ArrayList<>();
        List<SysProductRecordInto> opna = new ArrayList<>();

        List<SysProductRecordInto> wc1nb = new ArrayList<>();
        List<SysProductRecordInto> wc2nb = new ArrayList<>();
        List<SysProductRecordInto> yd1171nb = new ArrayList<>();
        List<SysProductRecordInto> yd1172nb = new ArrayList<>();
        List<SysProductRecordInto> p2nb = new ArrayList<>();
        List<SysProductRecordInto> p1nb = new ArrayList<>();
        List<SysProductRecordInto> opnb = new ArrayList<>();
        productRecordIntoList = productRecordIntoList.stream().filter(item -> item.getWorkPlan().getWorkPlanType().equals("普通订单")).collect(Collectors.toList());
        log.error("S1");
        lightAProductRecordIntoList = productRecordIntoList.stream().filter(
                item -> item.getShift().equals("白班") && item.getGroupName().equals("成型1组")).collect(Collectors.toList());
        lightBProductRecordIntoList = productRecordIntoList.stream().filter(
                item -> item.getShift().equals("白班") && item.getGroupName().equals("成型2组")).collect(Collectors.toList());
        nightAProductRecordIntoList = productRecordIntoList.stream().filter(
                item -> item.getShift().equals("夜班") && item.getGroupName().equals("成型1组")).collect(Collectors.toList());
        nightBProductRecordIntoList = productRecordIntoList.stream().filter(
                item -> item.getShift().equals("夜班") && item.getGroupName().equals("成型2组")).collect(Collectors.toList());
        log.error("S2");

        log.error("LIGHTA:{}", JSONObject.toJSONString(lightAProductRecordIntoList));
        log.error("LIGHTB:{}", JSONObject.toJSONString(lightBProductRecordIntoList));
        log.error("NightA:{}", JSONObject.toJSONString(nightAProductRecordIntoList));
        log.error("NightB:{}", JSONObject.toJSONString(nightBProductRecordIntoList));


        for (SysProductRecordInto productRecordInto : lightAProductRecordIntoList) {
            String productId = productRecordInto.getProductId();
            if (productId.startsWith("1.WC")) {
                wc1la.add(productRecordInto);
            } else if (productId.startsWith("2.WC")) {
                wc2la.add(productRecordInto);
            } else if (productId.startsWith("1.YD117") || productId.startsWith("1.YD1A") || productId.startsWith("1.YD1M")) {
                yd1171la.add(productRecordInto);
            } else if (productId.startsWith("2.YD117")) {
                yd1172la.add(productRecordInto);
            } else if (productId.startsWith("2.")) {
                p2la.add(productRecordInto);
            } else if (productId.startsWith("1.")) {
                p1la.add(productRecordInto);
            } else {
                opla.add(productRecordInto);
            }
        }
        for (SysProductRecordInto productRecordInto : lightBProductRecordIntoList) {
            String productId = productRecordInto.getProductId();
            if (productId.startsWith("1.WC")) {
                wc1lb.add(productRecordInto);
            } else if (productId.startsWith("2.WC")) {
                wc2lb.add(productRecordInto);
            } else if (productId.startsWith("1.YD117") || productId.startsWith("1.YD1A") || productId.startsWith("1.YD1M")) {
                yd1171lb.add(productRecordInto);
            } else if (productId.startsWith("2.YD117")) {
                yd1172lb.add(productRecordInto);
            } else if (productId.startsWith("2.")) {
                p2lb.add(productRecordInto);
            } else if (productId.startsWith("1.")) {
                p1lb.add(productRecordInto);
            } else {
                oplb.add(productRecordInto);
            }
        }
        for (SysProductRecordInto productRecordInto : nightAProductRecordIntoList) {
            String productId = productRecordInto.getProductId();
            if (productId.startsWith("1.WC")) {
                wc1na.add(productRecordInto);
            } else if (productId.startsWith("2.WC")) {
                wc2na.add(productRecordInto);
            } else if (productId.startsWith("1.YD117") || productId.startsWith("1.YD1A") || productId.startsWith("1.YD1M")) {
                yd1171na.add(productRecordInto);
            } else if (productId.startsWith("2.YD117")) {
                yd1172na.add(productRecordInto);
            } else if (productId.startsWith("2.")) {
                p2na.add(productRecordInto);
            } else if (productId.startsWith("1.")) {
                p1na.add(productRecordInto);
            } else {
                opna.add(productRecordInto);
            }
        }
        for (SysProductRecordInto productRecordInto : nightBProductRecordIntoList) {
            String productId = productRecordInto.getProductId();
            if (productId.startsWith("1.WC")) {
                wc1nb.add(productRecordInto);
            } else if (productId.startsWith("2.WC")) {
                wc2nb.add(productRecordInto);
            } else if (productId.startsWith("1.YD117") || productId.startsWith("1.YD1A") || productId.startsWith("1.YD1M")) {
                yd1171nb.add(productRecordInto);
            } else if (productId.startsWith("2.YD117")) {
                yd1172nb.add(productRecordInto);
            } else if (productId.startsWith("2.")) {
                p2nb.add(productRecordInto);
            } else if (productId.startsWith("1.")) {
                p1nb.add(productRecordInto);
            } else {
                opnb.add(productRecordInto);
            }
        }
        log.error("S3");

        if (!wc1la.isEmpty()) {
            ProductReceiptData wc1laProductData_2 = this.productReceiptUtil.getProductReceiptDataList(wc1la, wc1la.get(0), -2);
            ProductReceiptData wc1laProductData_1 = this.productReceiptUtil.getProductReceiptDataList(wc1la, wc1la.get(0), -1);
            ProductReceiptData wc1laProductData0 = this.productReceiptUtil.getProductReceiptDataList(wc1la, wc1la.get(0), 0);
            ProductReceiptData wc1laProductData1 = this.productReceiptUtil.getProductReceiptDataList(wc1la, wc1la.get(0), 1);
            ProductReceiptData wc1laProductData2 = this.productReceiptUtil.getProductReceiptDataList(wc1la, wc1la.get(0), 2);
//            ProductReceiptData wc1laProductData3 = this.productReceiptUtil.getProductReceiptDataList(wc1la, wc1la.get(0), 3);

            if (!wc1laProductData_2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_2 = this.productReceiptUtil.add(wc1laProductData_2);
                MiscellaneousDelivery miscellaneousDelivery = this.kingdeeUtils.getMiscellaneousDelivery1(wc1la);
                KingdeeResult kingdeeResult = this.kingdeeUtils.addMaterialInfo(miscellaneousDelivery);
//                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult_1, -2);
            }
            if (!wc1laProductData_1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_1 = this.productReceiptUtil.add(wc1laProductData_1);
                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult_1, -1);
            }
            if (!wc1laProductData1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult1 = this.productReceiptUtil.add(wc1laProductData1);
                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult1, 1);

            }
            if (!wc1laProductData2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult2 = this.productReceiptUtil.add(wc1laProductData2);
                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult2, 2);
            }
//            if (!wc1laProductData3.getData().getPage2().isEmpty()) {
//                KingdeeResult kingdeeResult3 = this.productReceiptUtil.add(wc1laProductData3);
//                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult3, 3);
//            }
            log.error("wc1laProductData_1:{}", JSONObject.toJSONString(wc1laProductData_1));
        }
        if (!wc2la.isEmpty()) {
            ProductReceiptData wc2laProductData_2 = this.productReceiptUtil.getProductReceiptDataList(wc2la, wc2la.get(0), -2);
            ProductReceiptData wc2laProductData_1 = this.productReceiptUtil.getProductReceiptDataList(wc2la, wc2la.get(0), -1);
            ProductReceiptData wc2laProductData0 = this.productReceiptUtil.getProductReceiptDataList(wc2la, wc2la.get(0), 0);
            ProductReceiptData wc2laProductData1 = this.productReceiptUtil.getProductReceiptDataList(wc2la, wc2la.get(0), 1);
            ProductReceiptData wc2laProductData2 = this.productReceiptUtil.getProductReceiptDataList(wc2la, wc2la.get(0), 2);
            if (!wc2laProductData_2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_2 = this.productReceiptUtil.add(wc2laProductData_2);
                MiscellaneousDelivery miscellaneousDelivery = this.kingdeeUtils.getMiscellaneousDelivery1(wc2la);
                KingdeeResult kingdeeResult = this.kingdeeUtils.addMaterialInfo(miscellaneousDelivery);
//                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult_1, -2);
            }
            if (!wc2laProductData_1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_1 = this.productReceiptUtil.add(wc2laProductData_1);
                this.productReceiptUtil.updateProductInto(wc2la, kingdeeResult_1, -1);
            }

//            if(!wc2laProductData0.getData().getPage2().isEmpty()) {
//                KingdeeResult kingdeeResult0 = this.productReceiptUtil.add(wc2laProductData0);
//                this.productReceiptUtil.updateProductInto(wc2la, kingdeeResult0, 0);
//
//            }
            if (!wc2laProductData1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult1 = this.productReceiptUtil.add(wc2laProductData1);
                this.productReceiptUtil.updateProductInto(wc2la, kingdeeResult1, 1);

            }
            if (!wc2laProductData2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult2 = this.productReceiptUtil.add(wc2laProductData2);
                this.productReceiptUtil.updateProductInto(wc2la, kingdeeResult2, 2);
            }

            log.error("wc2laProductData:{}", JSONObject.toJSONString(wc2laProductData_1));
        }
        log.error("YD11&");
        if (!yd1171la.isEmpty()) {
            ProductReceiptData yd1171laProductData_2 = this.productReceiptUtil.getProductReceiptDataList(yd1171la, yd1171la.get(0), -2);
            ProductReceiptData yd1171laProductData_1 = this.productReceiptUtil.getProductReceiptDataList(yd1171la, yd1171la.get(0), -1);
            ProductReceiptData yd1171laProductData0 = this.productReceiptUtil.getProductReceiptDataList(yd1171la, yd1171la.get(0), 0);
            ProductReceiptData yd1171laProductData1 = this.productReceiptUtil.getProductReceiptDataList(yd1171la, yd1171la.get(0), 1);
            ProductReceiptData yd1171laProductData2 = this.productReceiptUtil.getProductReceiptDataList(yd1171la, yd1171la.get(0), 2);
            log.error("JSONSSSSS:{}", JSONObject.toJSONString(yd1171laProductData_1));
            log.error("YD11&");
            if (!yd1171laProductData_2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_2 = this.productReceiptUtil.add(yd1171laProductData_2);
                MiscellaneousDelivery miscellaneousDelivery = this.kingdeeUtils.getMiscellaneousDelivery1(yd1171la);
                KingdeeResult kingdeeResult = this.kingdeeUtils.addMaterialInfo(miscellaneousDelivery);
//                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult_1, -2);
            }
            if (!yd1171laProductData_1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_1 = this.productReceiptUtil.add(yd1171laProductData_1);
                this.productReceiptUtil.updateProductInto(yd1171la, kingdeeResult_1, -1);
            }

            log.error("YD11&");
//            if(!yd1171laProductData0.getData().getPage2().isEmpty()) {
//                KingdeeResult kingdeeResult0 = this.productReceiptUtil.add(yd1171laProductData0);
//                this.productReceiptUtil.updateProductInto(yd1171la, kingdeeResult0, 0);
//
//            }
            if (!yd1171laProductData1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult1 = this.productReceiptUtil.add(yd1171laProductData1);
                this.productReceiptUtil.updateProductInto(wc2la, kingdeeResult1, 1);

            }
            if (!yd1171laProductData2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult2 = this.productReceiptUtil.add(yd1171laProductData2);
                this.productReceiptUtil.updateProductInto(yd1171la, kingdeeResult2, 2);
            }
            log.error("yd1171laProductData:{}", JSONObject.toJSONString(yd1171laProductData_1));
        }
        if (!yd1172la.isEmpty()) {
            ProductReceiptData yd1172laProductData_2 = this.productReceiptUtil.getProductReceiptDataList(yd1172la, yd1172la.get(0), -2);
            ProductReceiptData yd1172laProductData_1 = this.productReceiptUtil.getProductReceiptDataList(yd1172la, yd1172la.get(0), -1);
            ProductReceiptData yd1172laProductData0 = this.productReceiptUtil.getProductReceiptDataList(yd1172la, yd1172la.get(0), 0);
            ProductReceiptData yd1172laProductData1 = this.productReceiptUtil.getProductReceiptDataList(yd1172la, yd1172la.get(0), 1);
            ProductReceiptData yd1172laProductData2 = this.productReceiptUtil.getProductReceiptDataList(yd1172la, yd1172la.get(0), 2);

            if (!yd1172laProductData_2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_2 = this.productReceiptUtil.add(yd1172laProductData_2);
                MiscellaneousDelivery miscellaneousDelivery = this.kingdeeUtils.getMiscellaneousDelivery1(yd1172la);
                KingdeeResult kingdeeResult = this.kingdeeUtils.addMaterialInfo(miscellaneousDelivery);
//                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult_1, -2);
            }
            if (!yd1172laProductData_1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_1 = this.productReceiptUtil.add(yd1172laProductData_1);
                this.productReceiptUtil.updateProductInto(yd1172la, kingdeeResult_1, -1);
            }

//            if (!yd1172laProductData0.getData().getPage2().isEmpty()) {
//                KingdeeResult kingdeeResult0 = this.productReceiptUtil.add(yd1172laProductData0);
//                this.productReceiptUtil.updateProductInto(yd1172la, kingdeeResult0, 0);
//
//            }
            if (!yd1172laProductData1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult1 = this.productReceiptUtil.add(yd1172laProductData1);
                this.productReceiptUtil.updateProductInto(yd1172la, kingdeeResult1, 1);

            }
            if (!yd1172laProductData2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult2 = this.productReceiptUtil.add(yd1172laProductData2);
                this.productReceiptUtil.updateProductInto(yd1172la, kingdeeResult2, 2);
            }
            log.error("yd1172laProductData:{}", JSONObject.toJSONString(yd1172laProductData_1));
        }
        if (!p2la.isEmpty()) {
            ProductReceiptData p2laProductData_2 = this.productReceiptUtil.getProductReceiptDataList(p2la, p2la.get(0), -2);
            ProductReceiptData p2laProductData_1 = this.productReceiptUtil.getProductReceiptDataList(p2la, p2la.get(0), -1);
            ProductReceiptData p2laProductData0 = this.productReceiptUtil.getProductReceiptDataList(p2la, p2la.get(0), 0);
            ProductReceiptData p2laProductData1 = this.productReceiptUtil.getProductReceiptDataList(p2la, p2la.get(0), 1);
            ProductReceiptData p2laProductData2 = this.productReceiptUtil.getProductReceiptDataList(p2la, p2la.get(0), 2);

            if (!p2laProductData_2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_2 = this.productReceiptUtil.add(p2laProductData_2);
                MiscellaneousDelivery miscellaneousDelivery = this.kingdeeUtils.getMiscellaneousDelivery1(p2la);
                KingdeeResult kingdeeResult = this.kingdeeUtils.addMaterialInfo(miscellaneousDelivery);
//                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult_1, -2);
            }
            if (!p2laProductData_1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_1 = this.productReceiptUtil.add(p2laProductData_1);
                this.productReceiptUtil.updateProductInto(p2la, kingdeeResult_1, -1);
            }

//            if(!p2laProductData0.getData().getPage2().isEmpty()) {
//                KingdeeResult kingdeeResult0 = this.productReceiptUtil.add(p2laProductData0);
//                this.productReceiptUtil.updateProductInto(p2la, kingdeeResult0, 0);
//
//            }
            if (!p2laProductData1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult1 = this.productReceiptUtil.add(p2laProductData1);
                this.productReceiptUtil.updateProductInto(p2la, kingdeeResult1, 1);

            }
            if (!p2laProductData2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult2 = this.productReceiptUtil.add(p2laProductData2);
                this.productReceiptUtil.updateProductInto(p2la, kingdeeResult2, 2);
            }
            log.error("p2laProductData:{}", JSONObject.toJSONString(p2laProductData_1));
        }
        if (!p1la.isEmpty()) {
            ProductReceiptData p1laProductData_2 = this.productReceiptUtil.getProductReceiptDataList(p1la, p1la.get(0), -2);
            ProductReceiptData p1laProductData_1 = this.productReceiptUtil.getProductReceiptDataList(p1la, p1la.get(0), -1);
            ProductReceiptData p1laProductData0 = this.productReceiptUtil.getProductReceiptDataList(p1la, p1la.get(0), 0);
            ProductReceiptData p1laProductData1 = this.productReceiptUtil.getProductReceiptDataList(p1la, p1la.get(0), 1);
            ProductReceiptData p1laProductData2 = this.productReceiptUtil.getProductReceiptDataList(p1la, p1la.get(0), 2);
            if (!p1laProductData_2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_2 = this.productReceiptUtil.add(p1laProductData_2);
                MiscellaneousDelivery miscellaneousDelivery = this.kingdeeUtils.getMiscellaneousDelivery1(p1la);
                KingdeeResult kingdeeResult = this.kingdeeUtils.addMaterialInfo(miscellaneousDelivery);
//                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult_1, -2);
            }
            if (!p1laProductData_1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_1 = this.productReceiptUtil.add(p1laProductData_1);
                this.productReceiptUtil.updateProductInto(p1la, kingdeeResult_1, -1);
            }

//            if(!p1laProductData0.getData().getPage2().isEmpty()) {
//                KingdeeResult kingdeeResult0 = this.productReceiptUtil.add(p1laProductData0);
//                this.productReceiptUtil.updateProductInto(p1la, kingdeeResult0, 0);
//
//            }
            if (!p1laProductData1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult1 = this.productReceiptUtil.add(p1laProductData1);
                this.productReceiptUtil.updateProductInto(p1la, kingdeeResult1, 1);

            }
            if (!p1laProductData2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult2 = this.productReceiptUtil.add(p1laProductData2);
                this.productReceiptUtil.updateProductInto(p1la, kingdeeResult2, 2);
            }
            log.error("p1laProductData:{}", JSONObject.toJSONString(p1laProductData_1));
        }
        if (!opla.isEmpty()) {
            ProductReceiptData oplaProductData_2 = this.productReceiptUtil.getProductReceiptDataList(opla, opla.get(0), -2);
            ProductReceiptData oplaProductData_1 = this.productReceiptUtil.getProductReceiptDataList(opla, opla.get(0), -1);
            ProductReceiptData oplaProductData0 = this.productReceiptUtil.getProductReceiptDataList(opla, opla.get(0), 0);
            ProductReceiptData oplaProductData1 = this.productReceiptUtil.getProductReceiptDataList(opla, opla.get(0), 1);
            ProductReceiptData oplaProductData2 = this.productReceiptUtil.getProductReceiptDataList(opla, opla.get(0), 2);

            if (!oplaProductData_2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_2 = this.productReceiptUtil.add(oplaProductData_2);
                MiscellaneousDelivery miscellaneousDelivery = this.kingdeeUtils.getMiscellaneousDelivery1(opla);
                KingdeeResult kingdeeResult = this.kingdeeUtils.addMaterialInfo(miscellaneousDelivery);
//                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult_1, -2);
            }
            if (!oplaProductData_1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_1 = this.productReceiptUtil.add(oplaProductData_1);
                this.productReceiptUtil.updateProductInto(opla, kingdeeResult_1, -1);
            }
//
//            if(!oplaProductData0.getData().getPage2().isEmpty()) {
//                KingdeeResult kingdeeResult0 = this.productReceiptUtil.add(oplaProductData0);
//                this.productReceiptUtil.updateProductInto(opla, kingdeeResult0, 0);
//
//            }
            if (!oplaProductData1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult1 = this.productReceiptUtil.add(oplaProductData1);
                this.productReceiptUtil.updateProductInto(opla, kingdeeResult1, 1);

            }
            if (!oplaProductData2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult2 = this.productReceiptUtil.add(oplaProductData2);
                this.productReceiptUtil.updateProductInto(opla, kingdeeResult2, 2);
            }
            log.error("p1laProductData:{}", JSONObject.toJSONString(oplaProductData_1));
        }


        if (!wc1lb.isEmpty()) {
            ProductReceiptData wc1lbProductData_2 = this.productReceiptUtil.getProductReceiptDataList(wc1lb, wc1lb.get(0), -2);
            ProductReceiptData wc1lbProductData_1 = this.productReceiptUtil.getProductReceiptDataList(wc1lb, wc1lb.get(0), -1);
            ProductReceiptData wc1lbProductData0 = this.productReceiptUtil.getProductReceiptDataList(wc1lb, wc1lb.get(0), 0);
            ProductReceiptData wc1lbProductData1 = this.productReceiptUtil.getProductReceiptDataList(wc1lb, wc1lb.get(0), 1);
            ProductReceiptData wc1lbProductData2 = this.productReceiptUtil.getProductReceiptDataList(wc1lb, wc1lb.get(0), 2);
            if (!wc1lbProductData_2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_2 = this.productReceiptUtil.add(wc1lbProductData_2);
                MiscellaneousDelivery miscellaneousDelivery = this.kingdeeUtils.getMiscellaneousDelivery1(wc1lb);
                KingdeeResult kingdeeResult = this.kingdeeUtils.addMaterialInfo(miscellaneousDelivery);
//                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult_1, -2);
            }

            if (!wc1lbProductData_1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_1 = this.productReceiptUtil.add(wc1lbProductData_1);
                this.productReceiptUtil.updateProductInto(wc1lb, kingdeeResult_1, -1);
            }

//            if(!wc1lbProductData0.getData().getPage2().isEmpty()) {
//                KingdeeResult kingdeeResult0 = this.productReceiptUtil.add(wc1lbProductData0);
//                this.productReceiptUtil.updateProductInto(wc1lb, kingdeeResult0, 0);
//
//            }
            if (!wc1lbProductData1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult1 = this.productReceiptUtil.add(wc1lbProductData1);
                this.productReceiptUtil.updateProductInto(wc1lb, kingdeeResult1, 1);

            }
            if (!wc1lbProductData2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult2 = this.productReceiptUtil.add(wc1lbProductData2);
                this.productReceiptUtil.updateProductInto(wc1lb, kingdeeResult2, 2);
            }
            log.error("wc1lbProductData_1:{}", JSONObject.toJSONString(wc1lbProductData_1));
        }
        if (!wc2lb.isEmpty()) {
            ProductReceiptData wc2lbProductData_2 = this.productReceiptUtil.getProductReceiptDataList(wc2lb, wc2lb.get(0), -2);
            ProductReceiptData wc2lbProductData_1 = this.productReceiptUtil.getProductReceiptDataList(wc2lb, wc2lb.get(0), -1);
            ProductReceiptData wc2lbProductData0 = this.productReceiptUtil.getProductReceiptDataList(wc2lb, wc2lb.get(0), 0);
            ProductReceiptData wc2lbProductData1 = this.productReceiptUtil.getProductReceiptDataList(wc2lb, wc2lb.get(0), 1);
            ProductReceiptData wc2lbProductData2 = this.productReceiptUtil.getProductReceiptDataList(wc2lb, wc2lb.get(0), 2);

            if (!wc2lbProductData_2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_2 = this.productReceiptUtil.add(wc2lbProductData_2);
                MiscellaneousDelivery miscellaneousDelivery = this.kingdeeUtils.getMiscellaneousDelivery1(wc2lb);
                KingdeeResult kingdeeResult = this.kingdeeUtils.addMaterialInfo(miscellaneousDelivery);
//                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult_1, -2);
            }
            if (!wc2lbProductData_1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_1 = this.productReceiptUtil.add(wc2lbProductData_1);
                this.productReceiptUtil.updateProductInto(wc2lb, kingdeeResult_1, -1);
            }

//            if(!wc2lbProductData0.getData().getPage2().isEmpty()) {
//                KingdeeResult kingdeeResult0 = this.productReceiptUtil.add(wc2lbProductData0);
//                this.productReceiptUtil.updateProductInto(wc2lb, kingdeeResult0, 0);
//
//            }
            if (!wc2lbProductData1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult1 = this.productReceiptUtil.add(wc2lbProductData1);
                this.productReceiptUtil.updateProductInto(wc2lb, kingdeeResult1, 1);

            }
            if (!wc2lbProductData2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult2 = this.productReceiptUtil.add(wc2lbProductData2);
                this.productReceiptUtil.updateProductInto(wc2lb, kingdeeResult2, 2);
            }
        }
        if (!yd1171lb.isEmpty()) {
            ProductReceiptData yd1171lbProductData_2 = this.productReceiptUtil.getProductReceiptDataList(yd1171lb, yd1171lb.get(0), -2);
            ProductReceiptData yd1171lbProductData_1 = this.productReceiptUtil.getProductReceiptDataList(yd1171lb, yd1171lb.get(0), -1);
            ProductReceiptData yd1171lbProductData0 = this.productReceiptUtil.getProductReceiptDataList(yd1171lb, yd1171lb.get(0), 0);
            ProductReceiptData yd1171lbProductData1 = this.productReceiptUtil.getProductReceiptDataList(yd1171lb, yd1171lb.get(0), 1);
            ProductReceiptData yd1171lbProductData2 = this.productReceiptUtil.getProductReceiptDataList(yd1171lb, yd1171lb.get(0), 2);
            if (!yd1171lbProductData_2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_2 = this.productReceiptUtil.add(yd1171lbProductData_2);
                MiscellaneousDelivery miscellaneousDelivery = this.kingdeeUtils.getMiscellaneousDelivery1(yd1171lb);
                KingdeeResult kingdeeResult = this.kingdeeUtils.addMaterialInfo(miscellaneousDelivery);
//                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult_1, -2);
            }
            if (!yd1171lbProductData_1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_1 = this.productReceiptUtil.add(yd1171lbProductData_1);
                this.productReceiptUtil.updateProductInto(yd1171lb, kingdeeResult_1, -1);
            }

//            if(!yd1171lbProductData0.getData().getPage2().isEmpty()) {
//                KingdeeResult kingdeeResult0 = this.productReceiptUtil.add(yd1171lbProductData0);
//                this.productReceiptUtil.updateProductInto(yd1171lb, kingdeeResult0, 0);
//
//            }
            if (!yd1171lbProductData1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult1 = this.productReceiptUtil.add(yd1171lbProductData1);
                this.productReceiptUtil.updateProductInto(yd1171lb, kingdeeResult1, 1);

            }
            if (!yd1171lbProductData2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult2 = this.productReceiptUtil.add(yd1171lbProductData2);
                this.productReceiptUtil.updateProductInto(yd1171lb, kingdeeResult2, 2);
            }
            log.error("yd1171lbProductData:{}", JSONObject.toJSONString(yd1171lbProductData_1));
        }
        if (!yd1172lb.isEmpty()) {
            ProductReceiptData yd1172lbProductData_2 = this.productReceiptUtil.getProductReceiptDataList(yd1172lb, yd1172lb.get(0), -2);
            ProductReceiptData yd1172lbProductData_1 = this.productReceiptUtil.getProductReceiptDataList(yd1172lb, yd1172lb.get(0), -1);
            ProductReceiptData yd1172lbProductData0 = this.productReceiptUtil.getProductReceiptDataList(yd1172lb, yd1172lb.get(0), 0);
            ProductReceiptData yd1172lbProductData1 = this.productReceiptUtil.getProductReceiptDataList(yd1172lb, yd1172lb.get(0), 1);
            ProductReceiptData yd1172lbProductData2 = this.productReceiptUtil.getProductReceiptDataList(yd1172lb, yd1172lb.get(0), 2);

            if (!yd1172lbProductData_2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_2 = this.productReceiptUtil.add(yd1172lbProductData_2);
                MiscellaneousDelivery miscellaneousDelivery = this.kingdeeUtils.getMiscellaneousDelivery1(yd1172lb);
                KingdeeResult kingdeeResult = this.kingdeeUtils.addMaterialInfo(miscellaneousDelivery);
//                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult_1, -2);
            }
            if (!yd1172lbProductData_1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_1 = this.productReceiptUtil.add(yd1172lbProductData_1);
                this.productReceiptUtil.updateProductInto(yd1172lb, kingdeeResult_1, -1);
            }

//            if(!yd1172lbProductData0.getData().getPage2().isEmpty()) {
//                KingdeeResult kingdeeResult0 = this.productReceiptUtil.add(yd1172lbProductData0);
//                this.productReceiptUtil.updateProductInto(yd1172lb, kingdeeResult0, 0);
//
//            }
            if (!yd1172lbProductData1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult1 = this.productReceiptUtil.add(yd1172lbProductData1);
                this.productReceiptUtil.updateProductInto(yd1172lb, kingdeeResult1, 1);

            }
            if (!yd1172lbProductData2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult2 = this.productReceiptUtil.add(yd1172lbProductData2);
                this.productReceiptUtil.updateProductInto(yd1172lb, kingdeeResult2, 2);
            }
            log.error("yd1172lbProductData:{}", JSONObject.toJSONString(yd1172lbProductData_1));
        }
        if (!p2lb.isEmpty()) {
            ProductReceiptData p2lbProductData_2 = this.productReceiptUtil.getProductReceiptDataList(p2lb, p2lb.get(0), -2);
            ProductReceiptData p2lbProductData_1 = this.productReceiptUtil.getProductReceiptDataList(p2lb, p2lb.get(0), -1);
            ProductReceiptData p2lbProductData0 = this.productReceiptUtil.getProductReceiptDataList(p2lb, p2lb.get(0), 0);
            ProductReceiptData p2lbProductData1 = this.productReceiptUtil.getProductReceiptDataList(p2lb, p2lb.get(0), 1);
            ProductReceiptData p2lbProductData2 = this.productReceiptUtil.getProductReceiptDataList(p2lb, p2lb.get(0), 2);
            if (!p2lbProductData_2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_2 = this.productReceiptUtil.add(p2lbProductData_2);
                MiscellaneousDelivery miscellaneousDelivery = this.kingdeeUtils.getMiscellaneousDelivery1(p2lb);
                KingdeeResult kingdeeResult = this.kingdeeUtils.addMaterialInfo(miscellaneousDelivery);
//                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult_1, -2);
            }
            if (!p2lbProductData_1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_1 = this.productReceiptUtil.add(p2lbProductData_1);
                this.productReceiptUtil.updateProductInto(p2lb, kingdeeResult_1, -1);
            }

//            if(!p2lbProductData0.getData().getPage2().isEmpty()) {
//                KingdeeResult kingdeeResult0 = this.productReceiptUtil.add(p2lbProductData0);
//                this.productReceiptUtil.updateProductInto(p2lb, kingdeeResult0, 0);
//
//            }
            if (!p2lbProductData1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult1 = this.productReceiptUtil.add(p2lbProductData1);
                this.productReceiptUtil.updateProductInto(p2lb, kingdeeResult1, 1);

            }
            if (!p2lbProductData2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult2 = this.productReceiptUtil.add(p2lbProductData2);
                this.productReceiptUtil.updateProductInto(p2lb, kingdeeResult2, 2);
            }
            log.error("p2lbProductData:{}", JSONObject.toJSONString(p2lbProductData_1));
        }
        if (!p1lb.isEmpty()) {
            ProductReceiptData p1lbProductData_2 = this.productReceiptUtil.getProductReceiptDataList(p1lb, p1lb.get(0), -2);
            ProductReceiptData p1lbProductData_1 = this.productReceiptUtil.getProductReceiptDataList(p1lb, p1lb.get(0), -1);
            ProductReceiptData p1lbProductData0 = this.productReceiptUtil.getProductReceiptDataList(p1lb, p1lb.get(0), 0);
            ProductReceiptData p1lbProductData1 = this.productReceiptUtil.getProductReceiptDataList(p1lb, p1lb.get(0), 1);
            ProductReceiptData p1lbProductData2 = this.productReceiptUtil.getProductReceiptDataList(p1lb, p1lb.get(0), 2);

            if (!p1lbProductData_2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_2 = this.productReceiptUtil.add(p1lbProductData_2);
                MiscellaneousDelivery miscellaneousDelivery = this.kingdeeUtils.getMiscellaneousDelivery1(p1lb);
                KingdeeResult kingdeeResult = this.kingdeeUtils.addMaterialInfo(miscellaneousDelivery);
//                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult_1, -2);
            }
            if (!p1lbProductData_1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_1 = this.productReceiptUtil.add(p1lbProductData_1);
                this.productReceiptUtil.updateProductInto(p1lb, kingdeeResult_1, -1);
            }

//            if(!p1lbProductData0.getData().getPage2().isEmpty()) {
//                KingdeeResult kingdeeResult0 = this.productReceiptUtil.add(p1lbProductData0);
//                this.productReceiptUtil.updateProductInto(p1lb, kingdeeResult0, 0);
//
//            }
            if (!p1lbProductData1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult1 = this.productReceiptUtil.add(p1lbProductData1);
                this.productReceiptUtil.updateProductInto(p1lb, kingdeeResult1, 1);

            }
            if (!p1lbProductData2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult2 = this.productReceiptUtil.add(p1lbProductData2);
                this.productReceiptUtil.updateProductInto(p1lb, kingdeeResult2, 2);
            }
            log.error("p1lbProductData:{}", JSONObject.toJSONString(p1lbProductData_1));
        }
        if (!oplb.isEmpty()) {
            ProductReceiptData oplbProductData_2 = this.productReceiptUtil.getProductReceiptDataList(oplb, oplb.get(0), -2);
            ProductReceiptData oplbProductData_1 = this.productReceiptUtil.getProductReceiptDataList(oplb, oplb.get(0), -1);
            ProductReceiptData oplbProductData0 = this.productReceiptUtil.getProductReceiptDataList(oplb, oplb.get(0), 0);
            ProductReceiptData oplbProductData1 = this.productReceiptUtil.getProductReceiptDataList(oplb, oplb.get(0), 1);
            ProductReceiptData oplbProductData2 = this.productReceiptUtil.getProductReceiptDataList(oplb, oplb.get(0), 2);
            if (!oplbProductData_2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_2 = this.productReceiptUtil.add(oplbProductData_2);
                MiscellaneousDelivery miscellaneousDelivery = this.kingdeeUtils.getMiscellaneousDelivery1(oplb);
                KingdeeResult kingdeeResult = this.kingdeeUtils.addMaterialInfo(miscellaneousDelivery);
//                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult_1, -2);
            }

            if (!oplbProductData_1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_1 = this.productReceiptUtil.add(oplbProductData_1);
                this.productReceiptUtil.updateProductInto(oplb, kingdeeResult_1, -1);
            }

//            if(!oplbProductData0.getData().getPage2().isEmpty()) {
//                KingdeeResult kingdeeResult0 = this.productReceiptUtil.add(oplbProductData0);
//                this.productReceiptUtil.updateProductInto(oplb, kingdeeResult0, 0);
//
//            }
            if (!oplbProductData1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult1 = this.productReceiptUtil.add(oplbProductData1);
                this.productReceiptUtil.updateProductInto(oplb, kingdeeResult1, 1);

            }
            if (!oplbProductData2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult2 = this.productReceiptUtil.add(oplbProductData2);
                this.productReceiptUtil.updateProductInto(oplb, kingdeeResult2, 2);
            }
            log.error("p1lbProductData:{}", JSONObject.toJSONString(oplbProductData_1));
        }


        if (!wc1na.isEmpty()) {
            ProductReceiptData wc1naProductData_2 = this.productReceiptUtil.getProductReceiptDataList(wc1na, wc1na.get(0), -2);
            ProductReceiptData wc1naProductData_1 = this.productReceiptUtil.getProductReceiptDataList(wc1na, wc1na.get(0), -1);
            ProductReceiptData wc1naProductData0 = this.productReceiptUtil.getProductReceiptDataList(wc1na, wc1na.get(0), 0);
            ProductReceiptData wc1naProductData1 = this.productReceiptUtil.getProductReceiptDataList(wc1na, wc1na.get(0), 1);
            ProductReceiptData wc1naProductData2 = this.productReceiptUtil.getProductReceiptDataList(wc1na, wc1na.get(0), 2);
            if (!wc1naProductData_2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_2 = this.productReceiptUtil.add(wc1naProductData_2);
                MiscellaneousDelivery miscellaneousDelivery = this.kingdeeUtils.getMiscellaneousDelivery1(wc1na);
                KingdeeResult kingdeeResult = this.kingdeeUtils.addMaterialInfo(miscellaneousDelivery);
//                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult_1, -2);
            }
            if (!wc1naProductData_1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_1 = this.productReceiptUtil.add(wc1naProductData_1);
                this.productReceiptUtil.updateProductInto(wc1na, kingdeeResult_1, -1);
            }

//            if(!wc1naProductData0.getData().getPage2().isEmpty()) {
//                KingdeeResult kingdeeResult0 = this.productReceiptUtil.add(wc1naProductData0);
//                this.productReceiptUtil.updateProductInto(wc1na, kingdeeResult0, 0);
//
//            }
            if (!wc1naProductData1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult1 = this.productReceiptUtil.add(wc1naProductData1);
                this.productReceiptUtil.updateProductInto(wc1na, kingdeeResult1, 1);

            }
            if (!wc1naProductData2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult2 = this.productReceiptUtil.add(wc1naProductData2);
                this.productReceiptUtil.updateProductInto(wc1na, kingdeeResult2, 2);
            }
            log.error("wc1naProductData_1:{}", JSONObject.toJSONString(wc1naProductData_1));
        }
        if (!wc2na.isEmpty()) {
            ProductReceiptData wc2naProductData_2 = this.productReceiptUtil.getProductReceiptDataList(wc2na, wc2na.get(0), -2);
            ProductReceiptData wc2naProductData_1 = this.productReceiptUtil.getProductReceiptDataList(wc2na, wc2na.get(0), -1);
            ProductReceiptData wc2naProductData0 = this.productReceiptUtil.getProductReceiptDataList(wc2na, wc2na.get(0), 0);
            ProductReceiptData wc2naProductData1 = this.productReceiptUtil.getProductReceiptDataList(wc2na, wc2na.get(0), 1);
            ProductReceiptData wc2naProductData2 = this.productReceiptUtil.getProductReceiptDataList(wc2na, wc2na.get(0), 2);

            if (!wc2naProductData_2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_2 = this.productReceiptUtil.add(wc2naProductData_2);
                MiscellaneousDelivery miscellaneousDelivery = this.kingdeeUtils.getMiscellaneousDelivery1(wc2na);
                KingdeeResult kingdeeResult = this.kingdeeUtils.addMaterialInfo(miscellaneousDelivery);
//                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult_1, -2);
            }


            if (!wc2naProductData_1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_1 = this.productReceiptUtil.add(wc2naProductData_1);
                this.productReceiptUtil.updateProductInto(wc2na, kingdeeResult_1, -1);
            }

//            if(!wc2naProductData0.getData().getPage2().isEmpty()) {
//                KingdeeResult kingdeeResult0 = this.productReceiptUtil.add(wc2naProductData0);
//                this.productReceiptUtil.updateProductInto(wc2na, kingdeeResult0, 0);
//
//            }
            if (!wc2naProductData1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult1 = this.productReceiptUtil.add(wc2naProductData1);
                this.productReceiptUtil.updateProductInto(wc2na, kingdeeResult1, 1);

            }
            if (!wc2naProductData2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult2 = this.productReceiptUtil.add(wc2naProductData2);
                this.productReceiptUtil.updateProductInto(wc2na, kingdeeResult2, 2);
            }
            log.error("wc2naProductData:{}", JSONObject.toJSONString(wc2naProductData_1));
        }
        if (!yd1171na.isEmpty()) {
            ProductReceiptData yd1171naProductData_2 = this.productReceiptUtil.getProductReceiptDataList(yd1171na, yd1171na.get(0), -2);
            ProductReceiptData yd1171naProductData_1 = this.productReceiptUtil.getProductReceiptDataList(yd1171na, yd1171na.get(0), -1);
            ProductReceiptData yd1171naProductData0 = this.productReceiptUtil.getProductReceiptDataList(yd1171na, yd1171na.get(0), 0);
            ProductReceiptData yd1171naProductData1 = this.productReceiptUtil.getProductReceiptDataList(yd1171na, yd1171na.get(0), 1);
            ProductReceiptData yd1171naProductData2 = this.productReceiptUtil.getProductReceiptDataList(yd1171na, yd1171na.get(0), 2);

            if (!yd1171naProductData_2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_2 = this.productReceiptUtil.add(yd1171naProductData_2);
                MiscellaneousDelivery miscellaneousDelivery = this.kingdeeUtils.getMiscellaneousDelivery1(yd1171na);
                KingdeeResult kingdeeResult = this.kingdeeUtils.addMaterialInfo(miscellaneousDelivery);
//                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult_1, -2);
            }
            if (!yd1171naProductData_1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_1 = this.productReceiptUtil.add(yd1171naProductData_1);
                this.productReceiptUtil.updateProductInto(yd1171na, kingdeeResult_1, -1);
            }

//            if(!yd1171naProductData0.getData().getPage2().isEmpty()) {
//                KingdeeResult kingdeeResult0 = this.productReceiptUtil.add(yd1171naProductData0);
//                this.productReceiptUtil.updateProductInto(yd1171na, kingdeeResult0, 0);
//
//            }
            if (!yd1171naProductData1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult1 = this.productReceiptUtil.add(yd1171naProductData1);
                this.productReceiptUtil.updateProductInto(yd1171na, kingdeeResult1, 1);

            }
            if (!yd1171naProductData2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult2 = this.productReceiptUtil.add(yd1171naProductData2);
                this.productReceiptUtil.updateProductInto(yd1171na, kingdeeResult2, 2);
            }
            log.error("yd1171naProductData:{}", JSONObject.toJSONString(yd1171naProductData_1));
        }
        if (!yd1172na.isEmpty()) {
            ProductReceiptData yd1172naProductData_2 = this.productReceiptUtil.getProductReceiptDataList(yd1172na, yd1172na.get(0), -2);
            ProductReceiptData yd1172naProductData_1 = this.productReceiptUtil.getProductReceiptDataList(yd1172na, yd1172na.get(0), -1);
            ProductReceiptData yd1172naProductData0 = this.productReceiptUtil.getProductReceiptDataList(yd1172na, yd1172na.get(0), 0);
            ProductReceiptData yd1172naProductData1 = this.productReceiptUtil.getProductReceiptDataList(yd1172na, yd1172na.get(0), 1);
            ProductReceiptData yd1172naProductData2 = this.productReceiptUtil.getProductReceiptDataList(yd1172na, yd1172na.get(0), 2);

            if (!yd1172naProductData_2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_2 = this.productReceiptUtil.add(yd1172naProductData_2);
                MiscellaneousDelivery miscellaneousDelivery = this.kingdeeUtils.getMiscellaneousDelivery1(yd1172na);
                KingdeeResult kingdeeResult = this.kingdeeUtils.addMaterialInfo(miscellaneousDelivery);
//                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult_1, -2);
            }
            if (!yd1172naProductData_1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_1 = this.productReceiptUtil.add(yd1172naProductData_1);
                this.productReceiptUtil.updateProductInto(yd1172na, kingdeeResult_1, -1);
            }

//            if(!yd1172naProductData0.getData().getPage2().isEmpty()) {
//                KingdeeResult kingdeeResult0 = this.productReceiptUtil.add(yd1172naProductData0);
//                this.productReceiptUtil.updateProductInto(yd1172na, kingdeeResult0, 0);
//
//            }
            if (!yd1172naProductData1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult1 = this.productReceiptUtil.add(yd1172naProductData1);
                this.productReceiptUtil.updateProductInto(yd1172na, kingdeeResult1, 1);

            }
            if (!yd1172naProductData2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult2 = this.productReceiptUtil.add(yd1172naProductData2);
                this.productReceiptUtil.updateProductInto(yd1172na, kingdeeResult2, 2);
            }
            log.error("yd1172naProductData:{}", JSONObject.toJSONString(yd1172naProductData_1));
        }
        if (!p2na.isEmpty()) {
            ProductReceiptData p2naProductData_2 = this.productReceiptUtil.getProductReceiptDataList(p2na, p2na.get(0), -2);
            ProductReceiptData p2naProductData_1 = this.productReceiptUtil.getProductReceiptDataList(p2na, p2na.get(0), -1);
            ProductReceiptData p2naProductData0 = this.productReceiptUtil.getProductReceiptDataList(p2na, p2na.get(0), 0);
            ProductReceiptData p2naProductData1 = this.productReceiptUtil.getProductReceiptDataList(p2na, p2na.get(0), 1);
            ProductReceiptData p2naProductData2 = this.productReceiptUtil.getProductReceiptDataList(p2na, p2na.get(0), 2);

            if (!p2naProductData_2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_2 = this.productReceiptUtil.add(p2naProductData_2);
                MiscellaneousDelivery miscellaneousDelivery = this.kingdeeUtils.getMiscellaneousDelivery1(p2na);
                KingdeeResult kingdeeResult = this.kingdeeUtils.addMaterialInfo(miscellaneousDelivery);
//                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult_1, -2);
            }
            if (!p2naProductData_1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_1 = this.productReceiptUtil.add(p2naProductData_1);
                this.productReceiptUtil.updateProductInto(p2na, kingdeeResult_1, -1);
            }
//
//            if(!p2naProductData0.getData().getPage2().isEmpty()) {
//                KingdeeResult kingdeeResult0 = this.productReceiptUtil.add(p2naProductData0);
//                this.productReceiptUtil.updateProductInto(p2na, kingdeeResult0, 0);
//
//            }
            if (!p2naProductData1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult1 = this.productReceiptUtil.add(p2naProductData1);
                this.productReceiptUtil.updateProductInto(p2na, kingdeeResult1, 1);

            }
            if (!p2naProductData2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult2 = this.productReceiptUtil.add(p2naProductData2);
                this.productReceiptUtil.updateProductInto(p2na, kingdeeResult2, 2);
            }
            log.error("p2naProductData:{}", JSONObject.toJSONString(p2naProductData_1));
        }
        if (!p1na.isEmpty()) {
            ProductReceiptData p1naProductData_2 = this.productReceiptUtil.getProductReceiptDataList(p1na, p1na.get(0), -2);
            ProductReceiptData p1naProductData_1 = this.productReceiptUtil.getProductReceiptDataList(p1na, p1na.get(0), -1);
            ProductReceiptData p1naProductData0 = this.productReceiptUtil.getProductReceiptDataList(p1na, p1na.get(0), 0);
            ProductReceiptData p1naProductData1 = this.productReceiptUtil.getProductReceiptDataList(p1na, p1na.get(0), 1);
            ProductReceiptData p1naProductData2 = this.productReceiptUtil.getProductReceiptDataList(p1na, p1na.get(0), 2);

            if (!p1naProductData_2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_2 = this.productReceiptUtil.add(p1naProductData_2);
                MiscellaneousDelivery miscellaneousDelivery = this.kingdeeUtils.getMiscellaneousDelivery1(p1na);
                KingdeeResult kingdeeResult = this.kingdeeUtils.addMaterialInfo(miscellaneousDelivery);
//                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult_1, -2);
            }
            if (!p1naProductData_1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_1 = this.productReceiptUtil.add(p1naProductData_1);
                this.productReceiptUtil.updateProductInto(p1na, kingdeeResult_1, -1);
            }

//            if(!p1naProductData0.getData().getPage2().isEmpty()) {
//                KingdeeResult kingdeeResult0 = this.productReceiptUtil.add(p1naProductData0);
//                this.productReceiptUtil.updateProductInto(p1na, kingdeeResult0, 0);
//
//            }
            if (!p1naProductData1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult1 = this.productReceiptUtil.add(p1naProductData1);
                this.productReceiptUtil.updateProductInto(p1na, kingdeeResult1, 1);

            }
            if (!p1naProductData2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult2 = this.productReceiptUtil.add(p1naProductData2);
                this.productReceiptUtil.updateProductInto(p1na, kingdeeResult2, 2);
            }
            log.error("p1naProductData:{}", JSONObject.toJSONString(p1naProductData_1));
        }
        if (!opna.isEmpty()) {
            ProductReceiptData opnaProductData_2 = this.productReceiptUtil.getProductReceiptDataList(opna, opna.get(0), -2);
            ProductReceiptData opnaProductData_1 = this.productReceiptUtil.getProductReceiptDataList(opna, opna.get(0), -1);
            ProductReceiptData opnaProductData0 = this.productReceiptUtil.getProductReceiptDataList(opna, opna.get(0), 0);
            ProductReceiptData opnaProductData1 = this.productReceiptUtil.getProductReceiptDataList(opna, opna.get(0), 1);
            ProductReceiptData opnaProductData2 = this.productReceiptUtil.getProductReceiptDataList(opna, opna.get(0), 2);

            if (!opnaProductData_2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_2 = this.productReceiptUtil.add(opnaProductData_2);
                MiscellaneousDelivery miscellaneousDelivery = this.kingdeeUtils.getMiscellaneousDelivery1(opna);
                KingdeeResult kingdeeResult = this.kingdeeUtils.addMaterialInfo(miscellaneousDelivery);
//                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult_1, -2);
            }
            if (!opnaProductData_1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_1 = this.productReceiptUtil.add(opnaProductData_1);
                this.productReceiptUtil.updateProductInto(opna, kingdeeResult_1, -1);
            }

//            if(!opnaProductData0.getData().getPage2().isEmpty()) {
//                KingdeeResult kingdeeResult0 = this.productReceiptUtil.add(opnaProductData0);
//                this.productReceiptUtil.updateProductInto(opna, kingdeeResult0, 0);
//
//            }
            if (!opnaProductData1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult1 = this.productReceiptUtil.add(opnaProductData1);
                this.productReceiptUtil.updateProductInto(opna, kingdeeResult1, 1);

            }
            if (!opnaProductData2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult2 = this.productReceiptUtil.add(opnaProductData2);
                this.productReceiptUtil.updateProductInto(opna, kingdeeResult2, 2);
            }
            log.error("p2naProductData:{}", JSONObject.toJSONString(opnaProductData_1));
        }


        if (!wc1nb.isEmpty()) {
            ProductReceiptData wc1nbProductData_2 = this.productReceiptUtil.getProductReceiptDataList(wc1nb, wc1nb.get(0), -2);
            ProductReceiptData wc1nbProductData_1 = this.productReceiptUtil.getProductReceiptDataList(wc1nb, wc1nb.get(0), -1);
            ProductReceiptData wc1nbProductData0 = this.productReceiptUtil.getProductReceiptDataList(wc1nb, wc1nb.get(0), 0);
            ProductReceiptData wc1nbProductData1 = this.productReceiptUtil.getProductReceiptDataList(wc1nb, wc1nb.get(0), 1);
            ProductReceiptData wc1nbProductData2 = this.productReceiptUtil.getProductReceiptDataList(wc1nb, wc1nb.get(0), 2);

            if (!wc1nbProductData_2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_2 = this.productReceiptUtil.add(wc1nbProductData_2);
                MiscellaneousDelivery miscellaneousDelivery = this.kingdeeUtils.getMiscellaneousDelivery1(wc1nb);
                KingdeeResult kingdeeResult = this.kingdeeUtils.addMaterialInfo(miscellaneousDelivery);
//                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult_1, -2);
            }
            if (!wc1nbProductData_1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_1 = this.productReceiptUtil.add(wc1nbProductData_1);
                this.productReceiptUtil.updateProductInto(wc1nb, kingdeeResult_1, -1);
            }

//            if(!wc1nbProductData0.getData().getPage2().isEmpty()) {
//                KingdeeResult kingdeeResult0 = this.productReceiptUtil.add(wc1nbProductData0);
//                this.productReceiptUtil.updateProductInto(wc1nb, kingdeeResult0, 0);
//
//            }
            if (!wc1nbProductData1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult1 = this.productReceiptUtil.add(wc1nbProductData1);
                this.productReceiptUtil.updateProductInto(wc1nb, kingdeeResult1, 1);

            }
            if (!wc1nbProductData2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult2 = this.productReceiptUtil.add(wc1nbProductData2);
                this.productReceiptUtil.updateProductInto(wc1nb, kingdeeResult2, 2);
            }
            log.error("wc1nbProductData_1:{}", JSONObject.toJSONString(wc1nbProductData_1));
        }
        if (!wc2nb.isEmpty()) {
            ProductReceiptData wc2nbProductData_2 = this.productReceiptUtil.getProductReceiptDataList(wc2nb, wc2nb.get(0), -2);
            ProductReceiptData wc2nbProductData_1 = this.productReceiptUtil.getProductReceiptDataList(wc2nb, wc2nb.get(0), -1);
            ProductReceiptData wc2nbProductData0 = this.productReceiptUtil.getProductReceiptDataList(wc2nb, wc2nb.get(0), 0);
            ProductReceiptData wc2nbProductData1 = this.productReceiptUtil.getProductReceiptDataList(wc2nb, wc2nb.get(0), 1);
            ProductReceiptData wc2nbProductData2 = this.productReceiptUtil.getProductReceiptDataList(wc2nb, wc2nb.get(0), 2);
            if (!wc2nbProductData_2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_2 = this.productReceiptUtil.add(wc2nbProductData_2);
                MiscellaneousDelivery miscellaneousDelivery = this.kingdeeUtils.getMiscellaneousDelivery1(wc2nb);
                KingdeeResult kingdeeResult = this.kingdeeUtils.addMaterialInfo(miscellaneousDelivery);
//                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult_1, -2);
            }

            if (!wc2nbProductData_1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_1 = this.productReceiptUtil.add(wc2nbProductData_1);
                this.productReceiptUtil.updateProductInto(wc2nb, kingdeeResult_1, -1);
            }

//            if(!wc2nbProductData0.getData().getPage2().isEmpty()) {
//                KingdeeResult kingdeeResult0 = this.productReceiptUtil.add(wc2nbProductData0);
//                this.productReceiptUtil.updateProductInto(wc2nb, kingdeeResult0, 0);
//
//            }
            if (!wc2nbProductData1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult1 = this.productReceiptUtil.add(wc2nbProductData1);
                this.productReceiptUtil.updateProductInto(wc2nb, kingdeeResult1, 1);

            }
            if (!wc2nbProductData2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult2 = this.productReceiptUtil.add(wc2nbProductData2);
                this.productReceiptUtil.updateProductInto(wc2la, kingdeeResult2, 2);
            }
            log.error("wc2nbProductData:{}", JSONObject.toJSONString(wc2nbProductData_1));
        }
        if (!yd1171nb.isEmpty()) {
            ProductReceiptData yd1171nbProductData_2 = this.productReceiptUtil.getProductReceiptDataList(yd1171nb, yd1171nb.get(0), -2);
            ProductReceiptData yd1171nbProductData_1 = this.productReceiptUtil.getProductReceiptDataList(yd1171nb, yd1171nb.get(0), -1);
            ProductReceiptData yd1171nbProductData0 = this.productReceiptUtil.getProductReceiptDataList(yd1171nb, yd1171nb.get(0), 0);
            ProductReceiptData yd1171nbProductData1 = this.productReceiptUtil.getProductReceiptDataList(yd1171nb, yd1171nb.get(0), 1);
            ProductReceiptData yd1171nbProductData2 = this.productReceiptUtil.getProductReceiptDataList(yd1171nb, yd1171nb.get(0), 2);

            if (!yd1171nbProductData_2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_2 = this.productReceiptUtil.add(yd1171nbProductData_2);
                MiscellaneousDelivery miscellaneousDelivery = this.kingdeeUtils.getMiscellaneousDelivery1(yd1171nb);
                KingdeeResult kingdeeResult = this.kingdeeUtils.addMaterialInfo(miscellaneousDelivery);
//                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult_1, -2);
            }
            if (!yd1171nbProductData_1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_1 = this.productReceiptUtil.add(yd1171nbProductData_1);
                this.productReceiptUtil.updateProductInto(yd1171nb, kingdeeResult_1, -1);
            }

//            if(!yd1171nbProductData0.getData().getPage2().isEmpty()) {
//                KingdeeResult kingdeeResult0 = this.productReceiptUtil.add(yd1171nbProductData0);
//                this.productReceiptUtil.updateProductInto(yd1171nb, kingdeeResult0, 0);
//
//            }
            if (!yd1171nbProductData1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult1 = this.productReceiptUtil.add(yd1171nbProductData1);
                this.productReceiptUtil.updateProductInto(yd1171nb, kingdeeResult1, 1);

            }
            if (!yd1171nbProductData2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult2 = this.productReceiptUtil.add(yd1171nbProductData2);
                this.productReceiptUtil.updateProductInto(yd1171nb, kingdeeResult2, 2);
            }
            log.error("yd1171nbProductData:{}", JSONObject.toJSONString(yd1171nbProductData_1));
        }
        if (!yd1172nb.isEmpty()) {
            ProductReceiptData yd1172nbProductData_2 = this.productReceiptUtil.getProductReceiptDataList(yd1172nb, yd1172nb.get(0), -2);
            ProductReceiptData yd1172nbProductData_1 = this.productReceiptUtil.getProductReceiptDataList(yd1172nb, yd1172nb.get(0), -1);
            ProductReceiptData yd1172nbProductData0 = this.productReceiptUtil.getProductReceiptDataList(yd1172nb, yd1172nb.get(0), 0);
            ProductReceiptData yd1172nbProductData1 = this.productReceiptUtil.getProductReceiptDataList(yd1172nb, yd1172nb.get(0), 1);
            ProductReceiptData yd1172nbProductData2 = this.productReceiptUtil.getProductReceiptDataList(yd1172nb, yd1172nb.get(0), 2);

            if (!yd1172nbProductData_2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_2 = this.productReceiptUtil.add(yd1172nbProductData_2);
                MiscellaneousDelivery miscellaneousDelivery = this.kingdeeUtils.getMiscellaneousDelivery1(yd1172nb);
                KingdeeResult kingdeeResult = this.kingdeeUtils.addMaterialInfo(miscellaneousDelivery);
//                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult_1, -2);
            }
            if (!yd1172nbProductData_1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_1 = this.productReceiptUtil.add(yd1172nbProductData_1);
                this.productReceiptUtil.updateProductInto(yd1172nb, kingdeeResult_1, -1);
            }

//            if(!yd1172nbProductData0.getData().getPage2().isEmpty()) {
//                KingdeeResult kingdeeResult0 = this.productReceiptUtil.add(yd1172nbProductData0);
//                this.productReceiptUtil.updateProductInto(yd1172nb, kingdeeResult0, 0);
//
//            }
            if (!yd1172nbProductData1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult1 = this.productReceiptUtil.add(yd1172nbProductData1);
                this.productReceiptUtil.updateProductInto(yd1172nb, kingdeeResult1, 1);

            }
            if (!yd1172nbProductData2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult2 = this.productReceiptUtil.add(yd1172nbProductData2);
                this.productReceiptUtil.updateProductInto(yd1172nb, kingdeeResult2, 2);
            }
            log.error("yd1172nbProductData:{}", JSONObject.toJSONString(yd1172nbProductData_1));
        }
        if (!p2nb.isEmpty()) {
            ProductReceiptData p2nbProductData_2 = this.productReceiptUtil.getProductReceiptDataList(p2nb, p2nb.get(0), -2);
            ProductReceiptData p2nbProductData_1 = this.productReceiptUtil.getProductReceiptDataList(p2nb, p2nb.get(0), -1);
            ProductReceiptData p2nbProductData0 = this.productReceiptUtil.getProductReceiptDataList(p2nb, p2nb.get(0), 0);
            ProductReceiptData p2nbProductData1 = this.productReceiptUtil.getProductReceiptDataList(p2nb, p2nb.get(0), 1);
            ProductReceiptData p2nbProductData2 = this.productReceiptUtil.getProductReceiptDataList(p2nb, p2nb.get(0), 2);

            if (!p2nbProductData_2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_2 = this.productReceiptUtil.add(p2nbProductData_2);
                MiscellaneousDelivery miscellaneousDelivery = this.kingdeeUtils.getMiscellaneousDelivery1(p2nb);
                KingdeeResult kingdeeResult = this.kingdeeUtils.addMaterialInfo(miscellaneousDelivery);
//                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult_1, -2);
            }

            if (!p2nbProductData_1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_1 = this.productReceiptUtil.add(p2nbProductData_1);
                this.productReceiptUtil.updateProductInto(p2nb, kingdeeResult_1, -1);
            }

//            if(!p2nbProductData0.getData().getPage2().isEmpty()) {
//                KingdeeResult kingdeeResult0 = this.productReceiptUtil.add(p2nbProductData0);
//                this.productReceiptUtil.updateProductInto(p2nb, kingdeeResult0, 0);
//
//            }
            if (!p2nbProductData1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult1 = this.productReceiptUtil.add(p2nbProductData1);
                this.productReceiptUtil.updateProductInto(p2nb, kingdeeResult1, 1);

            }
            if (!p2nbProductData2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult2 = this.productReceiptUtil.add(p2nbProductData2);
                this.productReceiptUtil.updateProductInto(p2nb, kingdeeResult2, 2);
            }
            log.error("p2nbProductData:{}", JSONObject.toJSONString(p2nbProductData_1));
        }
        if (!p1nb.isEmpty()) {
            ProductReceiptData p1nbProductData_2 = this.productReceiptUtil.getProductReceiptDataList(p1nb, p1nb.get(0), -2);
            ProductReceiptData p1nbProductData_1 = this.productReceiptUtil.getProductReceiptDataList(p1nb, p1nb.get(0), -1);
            ProductReceiptData p1nbProductData0 = this.productReceiptUtil.getProductReceiptDataList(p1nb, p1nb.get(0), 0);
            ProductReceiptData p1nbProductData1 = this.productReceiptUtil.getProductReceiptDataList(p1nb, p1nb.get(0), 1);
            ProductReceiptData p1nbProductData2 = this.productReceiptUtil.getProductReceiptDataList(p1nb, p1nb.get(0), 2);
            if (!p1nbProductData_2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_2 = this.productReceiptUtil.add(p1nbProductData_2);
                MiscellaneousDelivery miscellaneousDelivery = this.kingdeeUtils.getMiscellaneousDelivery1(p1nb);
                KingdeeResult kingdeeResult = this.kingdeeUtils.addMaterialInfo(miscellaneousDelivery);
//                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult_1, -2);
            }
            if (!p1nbProductData_1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_1 = this.productReceiptUtil.add(p1nbProductData_1);
                this.productReceiptUtil.updateProductInto(p1nb, kingdeeResult_1, -1);
            }

//            if(!p1nbProductData0.getData().getPage2().isEmpty()) {
//                KingdeeResult kingdeeResult0 = this.productReceiptUtil.add(p1nbProductData0);
//                this.productReceiptUtil.updateProductInto(p1nb, kingdeeResult0, 0);
//
//            }
            if (!p1nbProductData1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult1 = this.productReceiptUtil.add(p1nbProductData1);
                this.productReceiptUtil.updateProductInto(p1nb, kingdeeResult1, 1);

            }
            if (!p1nbProductData2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult2 = this.productReceiptUtil.add(p1nbProductData2);
                this.productReceiptUtil.updateProductInto(p1nb, kingdeeResult2, 2);
            }
            log.error("p1nbProductData:{}", JSONObject.toJSONString(p1nbProductData_1));
        }
        if (!opnb.isEmpty()) {
            ProductReceiptData opnbProductData_2 = this.productReceiptUtil.getProductReceiptDataList(opnb, opnb.get(0), -2);
            ProductReceiptData opnbProductData_1 = this.productReceiptUtil.getProductReceiptDataList(opnb, opnb.get(0), -1);
            ProductReceiptData opnbProductData0 = this.productReceiptUtil.getProductReceiptDataList(opnb, opnb.get(0), 0);
            ProductReceiptData opnbProductData1 = this.productReceiptUtil.getProductReceiptDataList(opnb, opnb.get(0), 1);
            ProductReceiptData opnbProductData2 = this.productReceiptUtil.getProductReceiptDataList(opnb, opnb.get(0), 2);
            if (!opnbProductData_2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_2 = this.productReceiptUtil.add(opnbProductData_2);
                MiscellaneousDelivery miscellaneousDelivery = this.kingdeeUtils.getMiscellaneousDelivery1(opnb);
                KingdeeResult kingdeeResult = this.kingdeeUtils.addMaterialInfo(miscellaneousDelivery);
//                this.productReceiptUtil.updateProductInto(wc1la, kingdeeResult_1, -2);
            }

            if (!opnbProductData_1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult_1 = this.productReceiptUtil.add(opnbProductData_1);
                this.productReceiptUtil.updateProductInto(opnb, kingdeeResult_1, -1);
            }

//            if(!opnbProductData0.getData().getPage2().isEmpty()) {
//                KingdeeResult kingdeeResult0 = this.productReceiptUtil.add(opnbProductData0);
//                this.productReceiptUtil.updateProductInto(opnb, kingdeeResult0, 0);
//
//            }
            if (!opnbProductData1.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult1 = this.productReceiptUtil.add(opnbProductData1);
                this.productReceiptUtil.updateProductInto(opnb, kingdeeResult1, 1);

            }
            if (!opnbProductData2.getData().getPage2().isEmpty()) {
                KingdeeResult kingdeeResult2 = this.productReceiptUtil.add(opnbProductData2);
                this.productReceiptUtil.updateProductInto(opnb, kingdeeResult2, 2);
            }
            log.error("p2naProductData:{}", JSONObject.toJSONString(opnbProductData_1));


        }
        stopWatch.stop();
        log.error("制单共耗时：{}", stopWatch.getTotalTimeSeconds());
        QueryWrapper queryWrapper = QueryWrapper.create();
//        queryWrapper.where(SYS_PRODUCT_RECORD_INTO.TOTAL_HANDLE_INTO.gt(0));
//        queryWrapper.where(SYS_PRODUCT_RECORD_INTO.PRODUCT_DATE.eq(productDate));
//
//        List<SysProductRecordInto> productRecordIntos=this.sysProductRecordIntoService.list(queryWrapper);
//        for(SysProductRecordInto productRecordInto:productRecordIntos){
        queryWrapper = QueryWrapper.create();
//            queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION_RECORD.PRODUCT_RECORD_INTO_ID.eq(productRecordInto.getId()));
        queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION_RECORD.PRODUCT_DATE_INTO.eq(productDate));
        queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION_RECORD.NUM.gt(0));
//        queryWrapper.where(SYS_PRODUCT_RECORD_DETENTION_RECORD.PRODUCT_RECORD_INTO_ID.isNotNull());
        List<SysProductRecordDetentionRecord> sysProductRecordDetentionRecordList = this.sysProductRecordDetentionRecordService.getMapper().selectListWithRelationsByQuery(queryWrapper);
        List<TransferModel> transferModelList = this.transferDataUtil.getTransferDataList(sysProductRecordDetentionRecordList);
        for (TransferModel transferModel : transferModelList) {
            this.transferDataUtil.addAndUpdateTransferData1(transferModel);
        }

        List<SysProductRecordInto> productRecordIntoList1 = productRecordIntoList.stream().filter(item -> item.getWorkPlan().getWorkPlanType().equals("试产")).collect(Collectors.toList());
        if (!productRecordIntoList1.isEmpty()) {
            for (SysProductRecordInto productRecordInto : productRecordIntoList1) {
                List<SysProductRecordInto> productRecordIntoList2 = new ArrayList<>();
                productRecordIntoList2.add(productRecordInto);
                ProductReceiptData opnbProductData_1 = this.productReceiptUtil.getProductReceiptDataList(productRecordIntoList2, productRecordIntoList2.get(0), -1);
                ProductReceiptData opnbProductData0 = this.productReceiptUtil.getProductReceiptDataList(productRecordIntoList2, productRecordIntoList2.get(0), 0);
                ProductReceiptData opnbProductData1 = this.productReceiptUtil.getProductReceiptDataList(productRecordIntoList2, productRecordIntoList2.get(0), 1);
                ProductReceiptData opnbProductData2 = this.productReceiptUtil.getProductReceiptDataList(productRecordIntoList2, productRecordIntoList2.get(0), 2);
                if (!opnbProductData_1.getData().getPage2().isEmpty()) {
                    KingdeeResult kingdeeResult_1 = this.productReceiptUtil.add(opnbProductData_1);
                    this.productReceiptUtil.updateProductInto(opnb, kingdeeResult_1, -1);
                }

//            if(!opnbProductData0.getData().getPage2().isEmpty()) {
//                KingdeeResult kingdeeResult0 = this.productReceiptUtil.add(opnbProductData0);
//                this.productReceiptUtil.updateProductInto(opnb, kingdeeResult0, 0);
//
//            }
                if (!opnbProductData1.getData().getPage2().isEmpty()) {
                    KingdeeResult kingdeeResult1 = this.productReceiptUtil.add(opnbProductData1);
                    this.productReceiptUtil.updateProductInto(opnb, kingdeeResult1, 1);

                }
                if (!opnbProductData2.getData().getPage2().isEmpty()) {
                    KingdeeResult kingdeeResult2 = this.productReceiptUtil.add(opnbProductData2);
                    this.productReceiptUtil.updateProductInto(opnb, kingdeeResult2, 2);
                }
            }

        }

        return ResultTool.success();
    }

    //    **
//     * 分页查询。
//     *
//     * @param page 分页对象
//     * @return 分页对象
//     */
    @GetMapping("page")
    public Page<SysProductRecordInto> page(Page<SysProductRecordInto> page) {
        return sysProductRecordIntoService.page(page);
    }


    @PostMapping("/getProductIdList")
    public Result<?> getProductIdList(@RequestBody SysProductRecordInto productRecordInto) {
        QueryWrapper queryWrapper = QueryWrapper.create();
        queryWrapper.where(SYS_PRODUCT_RECORD_INTO.PRODUCT_DATE.between(productRecordInto.getStartDate(), productRecordInto.getEndDate()));
        if (productRecordInto.getShift() != null) {
            queryWrapper.where(SYS_PRODUCT_RECORD_INTO.SHIFT.eq(productRecordInto.getShift()));
        }
        queryWrapper.where(SYS_PRODUCT_RECORD_INTO.PRODUCT_ID.like(productRecordInto.getProductIdQuery()));
        queryWrapper.select(distinct(SYS_PRODUCT_RECORD_INTO.PRODUCT_ID));
        queryWrapper.orderBy(SYS_PRODUCT_RECORD_INTO.PRODUCT_ID, true);
        List<SysProductRecordInto> productRecordIntoList = this.sysProductRecordIntoService.list(queryWrapper);
        log.error("SysSQL:{}", JSONObject.toJSONString(queryWrapper.toSQL()));
        return productRecordIntoList.isEmpty() ? ResultTool.fail() : ResultTool.success(productRecordIntoList);
    }

    @Autowired
    SysBadRecordService sysBadRecordService;
    @Autowired
    SysPlcService sysPlcService;

    @PostMapping("/getProductDateIntoList")
    public Result<?> getProductDateIntoList(@RequestBody SysProductRecordInto productRecordInto) {
        QueryWrapper queryWrapper = QueryWrapper.create();
        queryWrapper.where(SYS_PRODUCT_RECORD_INTO.PRODUCT_DATE.between(productRecordInto.getStartDate(), productRecordInto.getEndDate()));
        if (productRecordInto.getShift() != null) {
            queryWrapper.where(SYS_PRODUCT_RECORD_INTO.SHIFT.eq(productRecordInto.getShift()));
        }
        if (productRecordInto.getProductIds() != null) {
            if (productRecordInto.getProductIds().length > 0) {
                queryWrapper.where(SYS_PRODUCT_RECORD_INTO.PRODUCT_ID.in((Object) productRecordInto.getProductIds()));
            }
        }

        queryWrapper.orderBy(SYS_PRODUCT_RECORD_INTO.MACHINE_NAME, true);
        queryWrapper.orderBy(SYS_PRODUCT_RECORD_INTO.PRODUCT_DATE, true);
        queryWrapper.orderBy(SYS_PRODUCT_RECORD_INTO.SHIFT, false);
        RelationManager.addIgnoreRelations("productRecordShift", "sysMachinePlc");
//        List<ProductRecordIntoModel> productRecordIntoList=this.sysProductRecordIntoService.getMapper().selectListWithRelationsByQueryAs(queryWrapper,ProductRecordIntoModel.class);
        List<ProductRecordIntoModel> productRecordIntoList = this.sysProductRecordIntoService.getMapper().selectListWithRelationsByQueryAs(queryWrapper, ProductRecordIntoModel.class);

        for (ProductRecordIntoModel sysProductRecordInto : productRecordIntoList) {

            queryWrapper = QueryWrapper.create();
            queryWrapper.where(SYS_BAD_RECORD.SHIFT.eq(sysProductRecordInto.getShift()));
            queryWrapper.where(SYS_BAD_RECORD.PRODUCT_DATE.eq(fromDateToString("yyyy-MM-dd", sysProductRecordInto.getProductDate())));
            queryWrapper.where(SYS_BAD_RECORD.WORK_PLAN_ID.eq(sysProductRecordInto.getWorkPlanId()));
            queryWrapper.where(SYS_BAD_RECORD.WORK_SHOP_NAME.eq("成型车间"));
            queryWrapper.select(SYS_BAD_RECORD.REASON_TYPE, sum(SYS_BAD_RECORD.NUM).as("num"));
            queryWrapper.groupBy(SYS_BAD_RECORD.REASON_TYPE);
            List<SysBadRecord> badRecordList = this.sysBadRecordService.list(queryWrapper);
            sysProductRecordInto.setBadRecordList(badRecordList);

            queryWrapper = QueryWrapper.create();
//            queryWrapper.where(SYS_PRODUCT_PEOPLE.WORK_PLAN_ID.eq(sysProductRecordInto.getWorkPlanId()));
            queryWrapper.where(SYS_PRODUCT_PEOPLE.WORK_DATE.eq(fromDateToString("yyyy-MM-dd", sysProductRecordInto.getProductDate())));
            queryWrapper.where(SYS_PRODUCT_PEOPLE.SHIFT.eq(sysProductRecordInto.getShift()));
            queryWrapper.select(distinct(SYS_PRODUCT_PEOPLE.JOB_NO), SYS_PRODUCT_PEOPLE.USER_NAME);
            List<SysProductPeople> productPeopleList = this.sysProductPeopleService.list(queryWrapper);
            StringJoiner stringJoiner = new StringJoiner("，");
            for (SysProductPeople productPeople : productPeopleList) {
                stringJoiner.add(productPeople.getUserName());
            }
            sysProductRecordInto.setPeopleNum(productPeopleList.size());
            sysProductRecordInto.setPeopleName(stringJoiner.toString());
            long times = sysProductRecordInto.getActualEndTime().getTime() - sysProductRecordInto.getActualStartTime().getTime();
            double hours = times / (60 * 60 * 1000);
            BigDecimal bigDecimal = BigDecimal.valueOf(hours);
            double hour = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            double adjustTime = sysProductRecordInto.getAdjustMachineDuration() / 60;
            BigDecimal bigDecimal1 = BigDecimal.valueOf(adjustTime);
            hour = hour - bigDecimal1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            if (hour >= 5) {
                hour = hour - 0.5;
            }
            hour = hour <= 0 ? 11.5 : hour;
            sysProductRecordInto.setActualTimes(hour);
            hour = hour * 60 * 60;
            sysProductRecordInto.setActualCycle((int) ((int) (hour * sysProductRecordInto.getWorkPlan().getMoldNumber() / sysProductRecordInto.getTotalCount())));
//            log.error("SL:{}",sysProductRecordInto.getTotalCount()/hour );


        }
        log.error("SysSQL:{}", JSONObject.toJSONString(queryWrapper.toSQL()));

        return productRecordIntoList.isEmpty() ? ResultTool.fail() : ResultTool.success(productRecordIntoList);

    }

    @Autowired
    SysMachinePlcService sysMachinePlcService;

    @PostMapping("/getProductDateIntoDifferenceList")
    public Result<?> getProductDateIntoDifferenceList(@RequestBody SysProductRecordInto productRecordInto) {
        Map<String, Object> map = new HashMap<>();

        QueryWrapper queryWrapper = QueryWrapper.create();
        queryWrapper.where(SYS_PRODUCT_RECORD_INTO.PRODUCT_DATE.between(productRecordInto.getStartDate(), productRecordInto.getEndDate()));
        if (productRecordInto.getShift() != null) {
            queryWrapper.where(SYS_PRODUCT_RECORD_INTO.SHIFT.eq(productRecordInto.getShift()));
        }
        if (productRecordInto.getProductIds() != null) {
            if (productRecordInto.getProductIds().length > 0) {
                queryWrapper.where(SYS_PRODUCT_RECORD_INTO.PRODUCT_ID.in((Object) productRecordInto.getProductIds()));
            }
        }

        queryWrapper.orderBy(SYS_PRODUCT_RECORD_INTO.MACHINE_NAME, true);
        queryWrapper.orderBy(SYS_PRODUCT_RECORD_INTO.PRODUCT_DATE, true);
        queryWrapper.orderBy(SYS_PRODUCT_RECORD_INTO.SHIFT, false);
        RelationManager.addIgnoreRelations("productRecordShift");
//        List<ProductRecordIntoModel> productRecordIntoList=this.sysProductRecordIntoService.getMapper().selectListWithRelationsByQueryAs(queryWrapper,ProductRecordIntoModel.class);
        List<ProductRecordIntoModel> productRecordIntoList = this.sysProductRecordIntoService.getMapper().selectListWithRelationsByQueryAs(queryWrapper, ProductRecordIntoModel.class);

//        queryWrapper.where(SYS_MACHINE_PLC.I)
        List<SysMachinePlc> machinePlcList = this.sysMachinePlcService.list();

        queryWrapper = QueryWrapper.create();
        queryWrapper.where(SYS_BAD_RECORD.REASON_NAME.eq("调机不良"));
        queryWrapper.where(SYS_BAD_RECORD.PRODUCT_DATE.between(productRecordInto.getStartDate(), productRecordInto.getEndDate()));
        if (productRecordInto.getShift() != null) {
            queryWrapper.where(SYS_BAD_RECORD.SHIFT.eq(productRecordInto.getShift()));
        }
        queryWrapper.select(sum(SYS_BAD_RECORD.NUM).as("num"), SYS_BAD_RECORD.WORK_PLAN_ID, SYS_BAD_RECORD.MACHINE_NAME, SYS_BAD_RECORD.SHIFT);
        queryWrapper.groupBy(SYS_BAD_RECORD.MACHINE_NAME, SYS_BAD_RECORD.WORK_PLAN_ID, SYS_BAD_RECORD.SHIFT);
        List<SysBadRecord> badRecordList = this.sysBadRecordService.list(queryWrapper);
        for (ProductRecordIntoModel productRecordIntoModel : productRecordIntoList) {
            SysMachinePlc machinePlc = machinePlcList.stream().filter(item -> item.getMachineName().equals(productRecordIntoModel.getMachineName())).findFirst().orElse(null);
            if (machinePlc != null) {
                productRecordIntoModel.setMachine(machinePlc);
                if (productRecordIntoModel.getShiftCode().startsWith("A")) {
                    productRecordIntoModel.setJsy(machinePlc.getTechnicianA());
                    productRecordIntoModel.setZdh(machinePlc.getAutoTechnicianA());
                } else {
                    productRecordIntoModel.setJsy(machinePlc.getTechnicianB());
                    productRecordIntoModel.setZdh(machinePlc.getAutoTechnicianB());
                }
            }
            SysBadRecord badRecord = badRecordList.stream().filter(item -> item.getShift().equals(productRecordIntoModel.getShift()) && item.getMachineName().equals(productRecordIntoModel.getMachineName()) && item.getWorkPlanId().equals(productRecordIntoModel.getWorkPlanId())).findFirst().orElse(null);
            if (badRecord != null) {
                productRecordIntoModel.setTjbl(badRecord.getNum());
            }
        }
        return productRecordIntoList.isEmpty() ? ResultTool.fail() : ResultTool.success(productRecordIntoList);

    }

    @PostMapping("/getProductBadDataList/{pageNo}/{pageSize}")
    public Result<?> getProductBadDataList(@PathVariable long pageNo, @PathVariable long pageSize, @RequestBody SysProductRecordInto productRecordInto) {

        Map<String, Object> map = new HashMap<>();

        QueryWrapper queryWrapper = QueryWrapper.create();
        queryWrapper.where(SYS_PRODUCT_RECORD_INTO.PRODUCT_DATE.between(productRecordInto.getStartDate(), productRecordInto.getEndDate()));
        if (productRecordInto.getShift() != null) {
            queryWrapper.where(SYS_PRODUCT_RECORD_INTO.SHIFT.eq(productRecordInto.getShift()));
        }
        if (productRecordInto.getProductIds() != null) {
            if (productRecordInto.getProductIds().length > 0) {
                queryWrapper.where(SYS_PRODUCT_RECORD_INTO.PRODUCT_ID.in((Object) productRecordInto.getProductIds()));
            }
        }

        Page<ProductRecordIntoModel> productRecordIntoPage = new Page<>(pageNo, pageSize);
        queryWrapper.orderBy(SYS_PRODUCT_RECORD_INTO.MACHINE_NAME, true);
        queryWrapper.orderBy(SYS_PRODUCT_RECORD_INTO.PRODUCT_DATE, true);
        queryWrapper.orderBy(SYS_PRODUCT_RECORD_INTO.SHIFT, false);
        RelationManager.addIgnoreRelations("productRecordShift", "sysMachinePlc", "productInfo", "workPlan");
//        List<ProductRecordIntoModel> productRecordIntoList=this.sysProductRecordIntoService.getMapper().selectListWithRelationsByQueryAs(queryWrapper,ProductRecordIntoModel.class);
//        List<ProductRecordIntoModel> productRecordIntoList = this.sysProductRecordIntoService.getMapper().selectListWithRelationsByQueryAs(queryWrapper, ProductRecordIntoModel.class);
        Page<ProductRecordIntoModel> productRecordIntoModelPage = this.sysProductRecordIntoService.pageAs(productRecordIntoPage, queryWrapper, ProductRecordIntoModel.class);
        List<ProductRecordIntoModel> productRecordIntoList = productRecordIntoModelPage.getRecords();
        queryWrapper = QueryWrapper.create();
        queryWrapper.select(SYS_BAD_RECORD.REASON_TYPE, sum(SYS_BAD_RECORD.NUM).as("num"));
        queryWrapper.where(SYS_BAD_RECORD.PRODUCT_DATE.between(productRecordInto.getStartDate(), productRecordInto.getEndDate()));
//        queryWrapper.where(SYS_BAD_RECORD.REASON_TYPE.ne("品质领取"));
        queryWrapper.where(SYS_BAD_RECORD.WORK_SHOP.likeLeft("成型"));
//        queryWrapper.where(SYS_BAD_RECORD.REASON_NAME.ne("打油料调机"));

//        queryWrapper.where(SYS_BAD_RECORD.REASON_NAME.ne("打油料调机"));
        queryWrapper.groupBy(SYS_BAD_RECORD.REASON_TYPE);
        if (productRecordInto.getShift() != null) {
            queryWrapper.where(SYS_BAD_RECORD.SHIFT.eq(productRecordInto.getShift()));
        }


        queryWrapper.orderBy(SYS_BAD_RECORD.NUM, false);
        List<SysBadRecord> badReasonTypeList = this.sysBadRecordService.list(queryWrapper);
        map.put("reasonTypeList", badReasonTypeList);

        queryWrapper = QueryWrapper.create();
        queryWrapper.select(SYS_BAD_RECORD.REASON_NAME, SYS_BAD_RECORD.REASON_TYPE, sum(SYS_BAD_RECORD.NUM).as("num"), SYS_BAD_RECORD.TYPE);
        queryWrapper.where(SYS_BAD_RECORD.PRODUCT_DATE.between(productRecordInto.getStartDate(), productRecordInto.getEndDate()));
//        queryWrapper.where(SYS_BAD_RECORD.REASON_TYPE.ne("品质领取"));
        if (productRecordInto.getShift() != null) {
            queryWrapper.where(SYS_BAD_RECORD.SHIFT.eq(productRecordInto.getShift()));
        }
        if (productRecordInto.getProductIds() != null) {
            if (productRecordInto.getProductIds().length > 0) {
                queryWrapper.where(SYS_BAD_RECORD.PRODUCT_ID.in((Object) productRecordInto.getProductIds()));
            }
        }
        queryWrapper.groupBy(SYS_BAD_RECORD.REASON_TYPE, SYS_BAD_RECORD.REASON_NAME, SYS_BAD_RECORD.TYPE);
        List<SysBadRecord> badReasonNameList = this.sysBadRecordService.list(queryWrapper);
        map.put("reasonNameList", badReasonNameList);
        List<SysMachinePlc> machinePlcList = this.sysMachinePlcService.list();
        queryWrapper = QueryWrapper.create();
        queryWrapper.where(SYS_BAD_RECORD.PRODUCT_DATE.between(productRecordInto.getStartDate(), productRecordInto.getEndDate()));
        queryWrapper.where(SYS_BAD_RECORD.WORK_SHOP.likeLeft("成型"));
//        queryWrapper.where(SYS_BAD_RECORD.REASON_NAME.ne("打油料调机"));
        queryWrapper.select(SYS_BAD_RECORD.PRODUCT_DATE, SYS_BAD_RECORD.REASON_TYPE, SYS_BAD_RECORD.REASON_NAME, sum(SYS_BAD_RECORD.NUM).as("num"), SYS_BAD_RECORD.TYPE, SYS_BAD_RECORD.WORK_PLAN_ID, SYS_BAD_RECORD.MACHINE_NAME, SYS_BAD_RECORD.SHIFT);
        queryWrapper.groupBy(SYS_BAD_RECORD.PRODUCT_DATE, SYS_BAD_RECORD.REASON_TYPE, SYS_BAD_RECORD.REASON_NAME, SYS_BAD_RECORD.TYPE, SYS_BAD_RECORD.WORK_PLAN_ID, SYS_BAD_RECORD.MACHINE_NAME, SYS_BAD_RECORD.SHIFT);
        List<SysBadRecord> badRecordList = this.sysBadRecordService.list(queryWrapper);
        for (ProductRecordIntoModel sysProductRecordInto : productRecordIntoList) {
            List<SysBadRecord> badRecordList1 = badRecordList.stream().filter(item ->
                    item.getWorkPlanId().equals(sysProductRecordInto.getWorkPlanId())
                            && item.getShift().equals(sysProductRecordInto.getShift())
                            && item.getProductDate().equals(sysProductRecordInto.getProductDate())).collect(Collectors.toList());
            SysMachinePlc machinePlc = machinePlcList.stream().filter(item -> item.getMachineName().equals(sysProductRecordInto.getMachineName())).findFirst().orElse(null);
            if (machinePlc != null) {
                sysProductRecordInto.setMachine(machinePlc);
                if (sysProductRecordInto.getShiftCode().startsWith("A")) {
                    sysProductRecordInto.setJsy(machinePlc.getTechnicianA());
                    sysProductRecordInto.setZdh(machinePlc.getAutoTechnicianA());
                } else {
                    sysProductRecordInto.setJsy(machinePlc.getTechnicianB());
                    sysProductRecordInto.setZdh(machinePlc.getAutoTechnicianB());
                }
            }
            sysProductRecordInto.setBadRecordList(badRecordList1);
        }
        map.put("dataList", productRecordIntoList);
        map.put("totalRows", productRecordIntoModelPage.getTotalRow());
        map.put("totalPage", productRecordIntoModelPage.getTotalPage());

        return productRecordIntoList.isEmpty() ? ResultTool.fail() : ResultTool.success(map);

    }

    @PostMapping("export")
    public void exportExcelData(HttpServletResponse response) throws IOException {

        LocalDate start = LocalDate.of(2024, 9, 1);
        LocalDate end = LocalDate.of(2024, 9, 30);

        QueryWrapper queryWrapper = QueryWrapper.create();
        queryWrapper.where(SYS_PRODUCT_RECORD_INTO.PRODUCT_DATE.between(start, end));

        List<SysProductRecordInto> productRecordIntoList = this.sysProductRecordIntoService.getMapper().selectListWithRelationsByQuery(queryWrapper);
        List<ProductBadDataExcel> productBadDataExcelList = new ArrayList<>();
        productRecordIntoList.forEach(item -> {
            productBadDataExcelList.add(BeanUtil.toBean(item, ProductBadDataExcel.class));
        });
        log.error("ProductInfoList:{}", JSONObject.toJSONString(productRecordIntoList));
        queryWrapper = QueryWrapper.create();
        queryWrapper.where(SYS_BAD_RECORD.PRODUCT_DATE.between(start, end));
        List<SysBadRecord> badRecordList = this.sysBadRecordService.list(queryWrapper);
        log.error("badRecordList:{}", JSONObject.toJSONString(badRecordList));
        List<String> reasonNameList = badRecordList.stream().map(SysBadRecord::getReasonName).distinct().collect(Collectors.toList());

        List<Map<String, String>> fileds = getFields(reasonNameList);
        log.error("Fileds:{}", fileds);
        // 导出 Excel
        ExcelUtils.write(response, "模具维修基础信息.xls", "数据", ProductBadDataExcel.class,
                productBadDataExcelList, reasonNameList, badRecordList);
    }

    public List<Map<String, String>> getFields(List<String> reasonList) {
        Field[] declaredFields = ProductBadDataExcel.class.getDeclaredFields();
        List<Map<String, String>> resultList = new ArrayList<>();

        for (Field field : declaredFields) {
            if (field.isAnnotationPresent(ExcelProperty.class)) {
                Map<String, String> map = new HashMap<>();
                String key = field.getAnnotation(ExcelProperty.class).value()[0];
                String name = null;

                if (field.isAnnotationPresent(ApiModelProperty.class)) {
                    name = field.getAnnotation(ApiModelProperty.class).value();
                }
                map.put("key", key);
                map.put("name", name);
                map.put("filedName", field.getName());
                resultList.add(map);

            }

        }
        reasonList.stream().forEach(item -> {
            Map<String, String> map = new HashMap<>();
            map.put("key", item);
            map.put("name", item);
            map.put("filedName", item);
            resultList.add(map);
        });
        return resultList;
    }
}
